和EntityContainer名称必须是不同的程序集独特之处? [英] The EntityContainer name must be unique in different assemblies?
问题描述
我有两个项目:
- News.Data li>
- Tags.Data LI >
这两个定义实体
。当我尝试使用(VAR DB =新News.Data.Entities(NAME =实体))$ B
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:
指定的模式是无效的。错误:
Model1.csdl(3,4):错误0019:在
EntityContainer相关名称必须是唯一的。
与实体已定义的名称
的EntityContainer相关。
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.
时有可能使用
News.Data.Entities
Tags.Data.Entities
而不是
News.Data.NewsEntities
Tags.Data.TagsEntities
推荐答案
<击>
的ConnectionStrings被配置在应用程序级,并且容器名称作为唯一的标识符。要么改变containerNames为唯一的价值,无论是重新实现的默认构造函数的的ObjectContext
来也许查找一个设置
,可在汇编级进行配置。
击>
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 a Setting
, which can be configured at assembly level.
编辑:
当创建一个实例的ObjectContext
, News.Data.Entities
在这个例子中,基类的背景通常用容器名称
构造。该参数给出了的ObjectContext
所有必要的信息,以使其存储连接,并做了所有的映射业务。
When creating an instance of an ObjectContext
, News.Data.Entities
in this example, the base class of your context is typically constructed with a ContainerName
. This parameter gives the ObjectContext
all the necessary information to make its store connection, and do all its mapping business.
基本上,一个协会是的ObjectContext
键入和容器名称$之间进行C $ C>。当实例化你的第二个方面
Tags.Data.Entities
,这是一个不同的类型,它会尝试与容器的类型相关联,这就是抛出异常,因为你不能在同一容器名称两次关联。
Basically, an association is made between the ObjectContext
type and the ContainerName
. When instantiating your second context Tags.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.
要解决这个问题,如果可以的话,最好的办法是重新创建EDMX,用不同的容器名称。如果删除不是一个选项,你可以修改设计的容器名称参数,然后破解用记事本打开EDMX,并查找EntitiesModelStoreContainer'和'实体'的一部分改为无论你的新容器名称是
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...
这篇关于和EntityContainer名称必须是不同的程序集独特之处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!