本文介绍了X里面已经包含了一个定义,Y中的EntityFramework? (简单的数据库)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3个表在我的MS SQL数据库,我已经加了的EntityFramework(最新的),我的项目,我已导入这3个表。第一个问题是,没有实体建造,所以我改变了code Genereation战略从默认

I have 3 tables in my MS SQL database and I have added a EntityFramework(latest) to my project where I have imported these 3 tables. The first problem was that no Entities was built so I changed "Code Genereation Strategy" from None to Default.

生成后,我得到

X里面已经包含Y的定义

在实体的所有属性。

在仔细研究它已经产生了部分的前 Users.cs 和一个部分用户 MainModel.Designer.cs

When looking closer it have generated a partial ex Users.cs and one partial User in in the MainModel.Designer.cs?

为什么会产生 User.cs ?我有一个类似的设置在另一个项目和EF设置了相同的设置,也没有 User.cs

Why is it generating User.cs? I have a similar setup in another project and the EF is set with the same settings, there is no User.cs?

EDIT1 :我看到有一点不同,和多数民众使用设置为False失败的项目强烈的空间类型,然而无法将其设置为true(灰色)

Edit1 : I can see one thing that differs and thats Use Strong Spatial Types that is set to False in the failing project, it is however not possible to set it to true(grayed)?

推荐答案

您应该要么使用 code代您.edmx文件的策略。或删除 MainModel.tt MainModel.Context.tt 模板,生成模型实体和上下文。

You should either use None code generation strategy for your .edmx file. Or remove MainModel.tt and MainModel.Context.tt templates, which generate model entities and context.

如果您使用默认 code生成策略,那么实体和上下文会生成到 MainModel.Designer.cs 文件。这将是标准的实体,从 EntityObject 继承,上下文会被继承的的ObjectContext 。随着实体框架5,我们有POCO实体生成。而整整一代人在T4模板,它产生的背景下,从的DbContext 继承和POCO实体没有一些基本类型(当然,只是对象)。完成

If you use Default code generation strategy, then entities and context will be generated into MainModel.Designer.cs file. That would be standard entities, inherited from EntityObject, context will be inherited of ObjectContext. With Entity Framework 5 we have POCO entities generation. And whole generation is done in T4 templates, which generate context, inherited from DbContext, and POCO entities without some base type (well, object only).

当你有两个模板,并启用code代EDMX设计,然后两组实体将会产生。这就是为什么你有名字的冲突。

When you have both templates and enabled code generation in edmx designer, then two sets of entities will be generated. That's why you have names conflict.

这篇关于X里面已经包含了一个定义,Y中的EntityFramework? (简单的数据库)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 02:58