EntityContainer名称在不同程序集中必须是唯一的?
我有两个项目:
- News.Data
- Tags.Data
都定义实体
。当我尝试
using (var db = new News.Data.Entities("name=Entities"))
{
results1 = db.News.ToList();
}
using (var db = new Tag.Data.Entities("name=Entities"))
{
results2 = db.Tag.ToList();
}
在控制台应用程序上执行时,出现此错误:
指定的架构无效。错误: Model1.csdl(3,4):错误0019: EntityContainer 名称必须是唯一的。 具有名称的 EntityContainer “实体”已定义。
是否可以使用
News.Data.Entities
Tags.Data.Entities
代替
News.Data.NewsEntities
Tags.Data.TagsEntities
?
I have two projects:
- News.Data
- Tags.Data
Both define Entities
. When I try to execute
using (var db = new News.Data.Entities("name=Entities"))
{
results1 = db.News.ToList();
}
using (var db = new Tag.Data.Entities("name=Entities"))
{
results2 = db.Tag.ToList();
}
on a console application I get this error:
Schema specified is not valid. Errors:
Model1.csdl(3,4) : error 0019: The
EntityContainer name must be unique.
An EntityContainer with the name
'Entities' is already defined.
Is it possible to use
News.Data.Entities
Tags.Data.Entities
instead of
News.Data.NewsEntities
Tags.Data.TagsEntities
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
<罢工>
连接字符串在应用程序级别配置,容器名称用作唯一标识符。要么将containerNames更改为唯一值,要么重新实现
ObjectContext
的默认构造函数以查找可以在程序集级别配置的Setting
。编辑
:
在本示例中创建
ObjectContext
、News.Data.Entities
的实例时,上下文的基类通常使用ContainerName
构造。此参数为ObjectContext
提供建立其存储连接并执行所有映射业务所需的所有信息。基本上,
ObjectContext
类型和ContainerName
之间建立了关联。当实例化第二个上下文Tags.Data.Entities
(这是一种不同的类型)时,它将尝试将该类型与容器关联起来,这就是引发异常的原因,因为您无法关联相同的类型ContainerName 两次。要解决此问题,如果可以的话,最好的办法是使用不同的容器名称重新创建 EDMX。如果无法删除,您可以在设计器中修改 ContainerName 参数,然后在记事本中打开 edmx,查找“EntitiesModelStoreContainer”,然后将“Entities”部分更改为新的 ContainerName。
希望它有帮助...
Connectionstrings are configured at application level, and the containername serves as a unique identifier. Either change the containerNames to a unique value, either reimplement the the default constructor of the
ObjectContext
to perhaps lookup aSetting
, which can be configured at assembly level.Edit:
When creating an instance of an
ObjectContext
,News.Data.Entities
in this example, the base class of your context is typically constructed with aContainerName
. This parameter gives theObjectContext
all the necessary information to make its store connection, and do all its mapping business.Basically, an association is made between the
ObjectContext
type and theContainerName
. When instantiating your second contextTags.Data.Entities
, which is a different type, it will try to associate the type with the container and this is what throws the exception, since you can't associate the same ContainerName twice.To address the issue, if you can, best thing would be to recreate the EDMX, with different container names. If deleting is not an option, you can modify the ContainerName parameter in the designer, then crack open the edmx in notepad, and look for 'EntitiesModelStoreContainer', and change the 'Entities' part to whatever your new ContainerName is.
Hope it helps...
我认为您已经尝试过:
您的问题是这两个项目具有相同的实体容器名称。您需要更改(至少)其中之一。
编辑:抱歉,回答你的确切问题......不!
I take it you've tried this:
Your problem is that the two projects have the same entity container name. You need to change (at least) one of them.
Edit: Sorry, to answer your exact question ... No!
问题可能不在于你的逻辑。当我在构建配置文件之间切换时,有时会遇到这种情况。为了解决这个问题,我删除了所有临时文件并进行了干净的构建。
The problem might not be with your logic. I encounter this sometimes when I switch between build profiles. To fix it, I delete all temporary files and do a clean build.