Entity Framework ObjectStateManager not defined

前端 未结 2 1069
生来不讨喜
生来不讨喜 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));
        };
    }
    

提交回复
热议问题