0

选择哪一个,ObjectContext或者DbContext,当有要求时,

  1. 数据建模由 Modeler 完成,并为 DEV 团队提供 sql 脚本。因此,我们选择了模型优先。这是一个正确的选择吗?
  2. 现有的非规范化数据库将迁移到建模器创建的新数据库
  3. 需要从 UI 维护字段级别的所有更新的审核日志
  4. 每个表都有CreatedBy, CreatedOn, ModifiedBy, ModifiedOn。这些字段应由 during 自动填充 context.SaveChanges()
4

2 回答 2

0

如果您正在启动一个新应用程序,只需使用 DbContext。如果需要,您可以随时深入到 ObjectContext。

  1. 如果您不喜欢设计器,您可以将 Code First 与 Migrations 一起使用,并通过 update-database -script 创建 SQL 脚本。

  2. 听起来像是 DBA 的任务?

  3. 逐个字段更改..如果这是一个断开连接的应用程序,您最好在 EF 之外处理它(恕我直言)

  4. 您可以为此轻松覆盖 SaveChanges。你在推文中说你有 dbcontext 书。有一个例子,我们使用基类来做到这一点。但是,如果您要先使用模型,请务必避免此问题:http: //msdn.microsoft.com/en-us/magazine/jj553510.aspx

于 2013-02-09T20:47:39.270 回答
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; }
}
于 2013-02-10T11:37:22.657 回答