当要求为<{1>}时,选择ObjectContext
或DbContext
。
CreatedBy
,CreatedOn
,ModifiedBy
,ModifiedOn
。这些
字段应该在期间自动填充
context.SaveChanges()
。答案 0 :(得分:0)
如果您要开始使用新应用,请使用DbContext。如果需要,您可以随时深入查看ObjectContext。
如果您不喜欢设计师,可以使用Code First with Migrations并通过update-database -script创建SQL脚本。
听起来像DBA的任务?
字段更改字段..如果这是一个断开连接的应用程序,您最好在EF(IMHO)之外处理
您可以轻松地覆盖SaveChanges。你在推文中说你有dbcontext书。有一个例子,我们使用基类来做到这一点。但是,如果您要首先使用模型,请务必避免此问题:http://msdn.microsoft.com/en-us/magazine/jj553510.aspx
答案 1 :(得分:0)
Thanks a lot Julie for your super quick response. You are The-EF-Angel.
I have read your MSDN article on Logging in EF.
To your reponse:
1. As a mandate, We need to use sql scripts provided by our Modeler to create our db. Also these scripts will be keep changing(With addition of new tables & update of exising schema) for each sprints. Hope DataFirst Model is fine. Whenever new we get new sql scripts, we plan to recreate the DB and update our EDMX. Do you see any issues with this approach ?
2. Ya we have a migration specialist for this task. I justed pointed that in question as an FYI.
3. We use MVC app and for field by field changes in audit log table, we planned to let EF decide what fields have changed(using change tracking ideas from your book) and capture that info into a DTO(we borrow your repository ideas from the course "EF in enterprise course" you authored in PS). And push that DTO into our messaging infrastructure and that will insert the audit logs to the DB.
Is this fine ? Do you foresee any issues ?
4. As you pointed out, we could change our interface for our needs by referring to your MSDN article and there "Figure 3 Setting the Interface’s DateCreated Property During SaveChanges"
I plan to use,
public interface ITheBaseType
{
DateTime DateCreated { get; set; }
DateTime DateModified { get; set; }
string CreatedBy { get; set; }
string ModifiedBy { get; set; }
}