2013-02-09 27 views
0

選擇哪一個或者ObjectContextDbContext,當要求,實體框架 - ObjectContext的或的DbContext當審計日誌和CreatedOn/ModifiedOn和DB建模團隊

  1. 數據建模由建模完成,提供了開發團隊一個sql 腳本。由於這個原因,我們選擇了Model First。這是一個正確的 的選擇?
  2. 現有的非規範化的數據庫將從UI
  3. 每個表都有CreatedBy遷移到由 建模
  4. 需要保持審計日誌全部更新創建新的數據庫,在外地一級, ,CreatedOnModifiedByModifiedOn。這些 字段應在 context.SaveChanges()期間自動填寫。
+0

這不是我清楚你實際上問。你能更具體地說明你感興趣的是什麼嗎? – 2013-02-09 20:42:51

回答

0

如果您正在開始一個新的應用程序,只需使用DbContext。如果需要,您總是可以深入到ObjectContext。

  1. 如果您不想使用設計器,可以使用Code First with Migrations並通過update-database -script創建SQL腳本。

  2. 聽起來像是DBA的任務嗎?

  3. 逐個字段changes..If這是一個斷開連接的應用程序,你會更好的處理EF(恕我直言)的那個以外

  4. 您可以輕鬆地覆蓋此調用SaveChanges。你在推文中說你有dbcontext書。這裏有一個例子,我們使用基類來做這件事。然而,如果你打算先用模型時,一定要避免這個問題:http://msdn.microsoft.com/en-us/magazine/jj553510.aspx

+0

我答覆回答。感謝您的意見。 – CGSK 2013-02-10 11:41:06

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; } 
}