【问题标题】:Entity Framework - ObjectContext or DbContext when AuditLog and CreatedOn/ModifiedOn and DB Modeling Team实体框架 - AuditLog 和 CreatedOn/ModifiedOn 以及 DB 建模团队时的 ObjectContext 或 DbContext
【发布时间】:2013-02-09 20:23:58
【问题描述】:

选择ObjectContextDbContext,当有要求时,

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

【问题讨论】:

  • 我不清楚你到底在问什么。请您更具体地说明您对什么感兴趣?

标签: dbcontext objectcontext


【解决方案1】:

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

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

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

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

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

【讨论】:

  • 我回复了作为答案。感谢您的 cmets。
【解决方案2】:
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; }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-07
    • 1970-01-01
    • 1970-01-01
    • 2012-03-04
    • 2011-07-30
    • 1970-01-01
    • 2010-09-29
    相关资源
    最近更新 更多