Entity Framework ObjectStateManager not defined

前端 未结 2 1049
生来不讨喜
生来不讨喜 2021-01-28 04:51

I have a distributed database that I thought might be nice to have events fire on updates so that all users get their data updated immediately and found this nice article; EF Ev

相关标签:
2条回答
  • 2021-01-28 05:25

    If your CertsModelContainer is a DbContext, you can cast it to an IObjectContextAdapter in order to access the ObjectStateManager.

    For example:

    using (CertsModelContainer db = new CertsModelContainer())
    {
        ((IObjectContextAdapter)db).ObjectStateManager.ObjectStateManagerChanged += (sender, e) =>
        {
            Console.WriteLine(string.Format(
                "ObjectStateManager.ObjectStateManagerChanged | Action: {0}, Object: {1}",
                e.Action,
                e.Element));
        };
    }
    
    0 讨论(0)
  • 2021-01-28 05:27

    Is CertsModelContainer a DbContext or an ObjectContext? Only the latter has an ObjectStateManager.

    If you are using transactions you could use Transaction.TransactionCompleted

    0 讨论(0)
提交回复
热议问题