我在我的实体类中为CreatedDate
设置默认值,如下所示。但在实施过程中,我得到了值01/01/0001
private DateTime _createdDate = DateTime.Now;
private DateTime _modifiedDate = DateTime.Now;
public DateTime CreatedDate
{
get { return _createdDate; }
set { _createdDate = value; }
}
public string LastModifiedBy { get; set; }
public DateTime LastModifiedDate
{
get { return _modifiedDate; }
set { _modifiedDate = value; }
}
这是我的实现
public bool AddJewelryItem(List<Entities.Jewelry> jewelryList)
{
bool isSuccess = false;
try
{
using (var db = new Context())
{
foreach (Entities.Jewelry jewelry in jewelryList)
{
db.JewelryItemsList.Add(jewelry.jewelryItems);
db.SaveChanges();
jewelry.jewelryAddnlDetails.JewelryID = jewelry.jewelryItems.JewelryID;
if (jewelry.jewelryAddnlDetails.JewelryID != 0)
{
db.JewelryAddnlDetailsList.Add(jewelry.jewelryAddnlDetails);
db.SaveChanges();
}
}
isSuccess = true;
}
}