在VS 2012使用实体数据模型

编程入门 行业动态 更新时间:2024-10-27 12:26:41
本文介绍了在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使用实体数据模型

本文发布于:2023-11-04 05:52:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1557125.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:实体   数据模型

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!