【发布时间】:2014-02-12 17:44:06
【问题描述】:
对于我正在开发的 ASP.NET MVC 应用程序,我的实体与预先存在的表相冲突,这些表具有旨在跟踪数据库事务的列(LastModDate、LastModByUserId、CreateDate、CreateByUserId),但未设置他们自己的触发器来自动填充这些列。我有点脱离了我的舒适区,因为过去我只使用通过数据库触发器填充这些列或手动完成事务跟踪但在单独的表中的表(通常是我在处理中看到的)与 ESB 和订购系统)。
我对为什么以这种方式设置这些列的假设是在用户经过身份验证但 Web 应用程序与数据库的连接是通过应用程序用户帐户完成的情况下覆盖与用户身份相关的字段。
所以我的问题是在设计映射到这些表的模型时,我是否只是扩展“DBEntity”类型类并在进行任何修改之前调用“更新/更新”例程?此外,这些类型的手动填充事务列是否常见?谢谢。
public class DBEntity
{
//Primary Key
public int Id { get; set; }
public DateTime LastModDate {get; set;}
public int LastModByUserId {get; set;}
public DateTime CreateDate {get; set;}
public int CreateByUserId {get; set;}
public DBEntity(UserLogin currentUser)
{
CreatedDate=DateTime.Now;
CreatedByUserId=currentUser.Id;
Updated (UserLogin);
}
public void Updated (UserLogin user)
{
LastModDate =DateTime.Now;
LastModUserId =user.Id;
}
}
public class UserLogin : DBEntity
{
public string Name { get; set; }
public string UserName { get; set; }
public string UserPassword { get; set; }
}
【问题讨论】:
标签: c# sql-server entity-framework theory