实体框架5名称空间 [英] Entity Framework 5 namespaces

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

问题描述

我想先将Entity Framework 5数据库添加到Visual Studio 2012中针对.net Framework 4.5的类库中。我对需要输入的所有标签感到困惑:

I want to add Entity Framework 5 database first into a class library in Visual Studio 2012 targeting .net framework 4.5. I am confused with all the labels I need to key in:


  • 将ADO.NET实体数据模型添加到项目中时的EDMX文件名。我将'MyEF.edmx'放入。

  • 将连接字符串保存到配置文件中时。我放置了 MyEntities。

  • 选择了要包含在模型中的表之后,有一个文本框可输入模型名称空间。我放置了 MyModel。

  • Myli.edmx文件的属性自定义工具名称空间。我放置了 TheEF。
    Myli.Context.tt文件的属性自定义工具名称空间。我放置了 TheContext。
    Myli.tt文件的属性自定义工具名称空间。我放了'TheModel'。
  • The EDMX file name when adding ADO.NET entity data model to the project. I put ‘MyEF.edmx’.
  • When saving the connection string into the config file. I put ‘MyEntities’.
  • After selecting some tables to include in my model, there’s a textbox to input model namespace. I put ‘MyModel’.
  • Property ‘custom tool namespace’ of the MyEF.edmx file. I put ‘TheEF’.
  • Property ‘custom tool namespace’ of the MyEF.Context.tt file. I put ‘TheContext’.
  • Property ‘custom tool namespace’ of the MyEF.tt file. I put ‘TheModel’.

用ADO.NET实体数据模型设计器打开MyEF.edmx,看一下MyModel的属性,

Opening MyEF.edmx with ADO.NET entity data model designer, looking at the properties of MyModel, there are:


  • 实体容器名称,其中填充了 MyEntities。因此,连接字符串的名称在此处。

  • 命名空间,其中填充了 MyModel。这来自表选择文本框。

将某些内容放入edmx自定义工具名称空间似乎没有任何作用。我之所以得出这个结论,是因为当我重复整个源代码文件夹时,我仅在vbproj文件中找到了它。

Putting something into the edmx custom tool namespace doesn’t seem to do anything. I got this conclusion because when I grep the entire source code folders, I found it only in a vbproj file.

将'TheModel'放入MyEF.tt自定义工具名称空间会生成MyEF.Context.vb错误,提示未定义类型 MyTable(这是我的数据库表的名称)。

Putting ‘TheModel’ into MyEF.tt custom tool namespace produces error from MyEF.Context.vb saying type ‘MyTable’ (this is the name of my database table) is not defined.

有人可以解释每个标签的用途吗?

Can someone explain the purpose of each label?

如果我要将由这个edmx生成的所有类(DbContext,模型等)放入一个名为MyEF的名称空间,

If I want to put all the classes generated by this one edmx (DbContext, models, etc.) into one namespace, ‘MyEF’, what should I put in each of those places?

推荐答案

各种属性的用法如下:


  • EDMX文件名->用于EDMX文件名

  • 连接字符串名->用于配置文件中的连接字符串名还用于EDMX的概念模型(CSDL)部分的容器名称

  • 模型名称空间->用于EDMX的概念模型(CSDL)部分的名称空间为圣附加了.Store的矿石模型(SSDL)零件

  • 用于EDMX文件的自定义工具名称空间->我不认为在使用T4代POCO实体时,它可用于任何东西。使用内置代码生成的EF1样式时,设置此属性将为所有生成的文件设置.NET命名空间。

  • .Context.tt文件的自定义工具命名空间-> .NET源文件中用于上下文的名称空间

  • .tt文件的自定义工具名称空间->实体源文件中使用的.NET名称空间

  • EDMX file name --> Used for the EDMX file name
  • Connection string name --> Used for the connection string name in the config file, and also for the container name of the conceptual model (CSDL) part of the EDMX
  • Model namespace --> Used for the namespace of the conceptual model (CSDL) part of the EDMX, and also for the store model (SSDL) part with .Store appended
  • Custom tool namespace for the EDMX file --> I don't believe this is used for anything when using T4 generation of POCO entities. When using EF1-style built in code generation, setting this property will set the .NET namespace for all generated files.
  • Custom tool namespace for .Context.tt file --> The .NET namespace used in the source file for the context
  • Custom tool namespace for .tt file --> The .NET namespace used in the source files for the entities

请注意,如果将.Context.tt和.tt自定义命名空间设置为不同的内容,则上下文将在与实体类型不同的命名空间中生成不会开箱即用地编译。如果您想在此处使用不同的名称空间,则可以更新.tt文件,但是更多的时候人们只是对两者使用相同的名称空间。

Note that if you set the .Context.tt and .tt custom namespaces to different things, then the context will be generated in a different namespace to the entity types and this won't compile out-of-the-box. You can update the .tt files if you want to use different namespaces here, but more often people just use the same namespace for both.

还请注意,您可能需要更改属性后,从上下文菜单中为每个.tt文件选择运行自定义工具,以便重新生成代码。

Also note that you may need to choose "Run Custom Tool" from the context menu for each .tt file after changing the properties in order for the code to be re-generated.

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

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