实体框架ObjectStateManager未定义 [英] Entity Framework ObjectStateManager not defined

查看:109
本文介绍了实体框架ObjectStateManager未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个分布式数据库,我认为在更新时触发事件可能会很好,这样所有用户都可以立即更新其数据并找到这篇不错的文章。 EF事件

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 Events

我从本文相信作为实体容器名称,在我的情况下为 CertsModelContainer

I'm led to believe from this article that the Context is defined as the Entity Container Name, which in my case is "CertsModelContainer"

但是,当我尝试时;

using (CertsModelContainer db = new CertsModelContainer())
{
    db.ObjectStateManager.ObjectStateManagerChanged += (sender, e) =>
    {
        Console.WriteLine(string.Format(
            "ObjectStateManager.ObjectStateManagerChanged | Action: {0}, Object: {1}",
            e.Action,
            e.Element));
    };
}

Visual Studio通知我CertsModelContainer不包含'ObjectStateManager'的定义

Visual studio informs me that CertsModelContainer does not contain a definition for 'ObjectStateManager'

我不确定为什么会这样以及如何解决它,有人可以帮帮我吗?

(我使用的是EF5,

I'm not sure why this is happening and how to fix it, could someone help me out?
(I'm using EF5 and used ModelFirst to generate my database if that makes any difference?)

推荐答案

CertsModelContainer是DbContext还是ObjectContext?

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

如果使用事务,则可以使用Transaction.TransactionCompleted

If you are using transactions you could use Transaction.TransactionCompleted

这篇关于实体框架ObjectStateManager未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆