【发布时间】:2014-09-04 08:02:38
【问题描述】:
我的实体类中包含了这个Complex Type,例如:
public class Logbook
{
public string CreatedBy { get; set; }
public DateTimeOffset DateCreated { get; set; }
public string ModifiedBy { get; set; }
public DateTimeOffset DateModified { get; set; }
}
然后是我的主课:
public class Customer
{
public int Id { get; set; }
public string Name { get; set; }
public Logbook Logbook { get; set; }
}
然后我将Logbook 类设置为复杂类型。我的问题是,我想知道如何在插入/修改Customer 实体后立即设置Logbook 中的值?比如说,将DateCreated 设置为DateTime.UtcNow 并将CreatedBy 设置为用户名......等等。任何帮助将非常感激。谢谢!
编辑:
我使用Entity Framework 进行数据访问。这就是我保存Customer
public ActionResult Create(Customer customer)
{
if ( Model.IsValid() )
{
_customerRepository.Insert(customer);
return View("Index");
}
return View(customer);
}
【问题讨论】:
-
你能展示你创建一个新
Customer的代码吗? -
保存
Customer之前还是之后? -
插入/更新是什么意思?实体框架?你使用存储库还是什么?
-
ps。还有很多关于此的有趣文章:google.com/…
标签: c# asp.net-mvc entity-framework