在VS 2012使用实体数据模型 [英] Using Entity Data Model in VS 2012

查看:482
本文介绍了在VS 2012使用实体数据模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用的实体数据模型之前,VS 2010,但现在我有VS 2012的麻烦。 首先,现在在2012年实体数据模型有与.TT扩展两个新文件。另外,Designer.cs文件是空的,并有消息如何启用code一代,但是当我做使code代它说,对象已经存在。

I have used Entity Data Model before with VS 2010, but now I am having trouble with VS 2012. First of all, now in 2012 Entity Data Model there are two new files with .tt extension. Also the Designer.cs file is empty and has a message how to enable the code generation, but when I do enable the code generation it says that the objects already exist.

我也错过了CreateObjectSet();

I am also missing the CreateObjectSet();

 using (MyEntities entitiesContext = new MyEntities())
            {
                var entitySet = entitiesContext.CreateObjectSet<T>();

            }

不知道为什么,但现在entitiesContext没有.CreateObjectSet();

Not sure why, but now the entitiesContext doesn't have the .CreateObjectSet();

我不知道是否有人能澄清到底是怎么回事。

I wonder if someone could clear up what is going on.

推荐答案

新的实体数据模型在VS 2012默认使用T4模板(.TT)文件,而不是以前的自定义工具,code一代。所生成的上下文还基于更新的DbContext的API,而不是使用由Visual Studio 2010(这就是为什么它不具有方法的原因的ObjectContext API - 中的DbContext API等效方法是集&其中; T&GT; )。无论T4和的DbContext API目前推荐的方法使用EF。

The new Entity Data Model in VS 2012 by default uses T4 templates (.tt) files instead of former custom tool for code generation. The generated context is also based newer DbContext API instead of ObjectContext API used by Visual Studio 2010 (that is the reason why it doesn't have the method - the equivalent method in DbContext API is Set<T>). Both T4 and DbContext API are currently recommended approach for using EF.

我没有VS 2012对我目前的机器,但你可以尝试是删除这两个.TT并打开老一代在 .Desinger.cs描述。

I don't have VS 2012 on my current machine but what you can try is to delete both .tt and turn on the old generation as described in .Desinger.cs.

这篇关于在VS 2012使用实体数据模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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