gpt4 book ai didi

c# - 项目包含多个 EDMX 文件时抛出 "the entity type is not part of the model for the current context"错误

转载 作者:太空狗 更新时间:2023-10-29 20:32:58 24 4
gpt4 key购买 nike

我首先使用数据库,我有一个看起来像这样的 switch 语句:

switch (site)
{
case Site.One:
using (OneContext one = new OneContext())
return one.OrganizationObjects.SingleOrDefault(x => x.u_Name == orgName)?.g_org_id;
case Site.Two:
using (TwoContext two = new TwoContext())
return two.OrganizationObjects.SingleOrDefault(x => x.u_Name == orgName)?.g_org_id;
default:
throw new NotImplementedException();
}

这两个数据库非常相似,并且具有几乎所有相同的模型。

如果我删除“Two”EDMX 文件并注释掉该条件,那么 OneContext 将完美运行。
如果我将 TwoContext EDMX 文件添加到项目并再次运行代码,“OneContext”代码在尝试查询 OrganizationObjects 时失败。

我确保每个上下文都使用了正确的连接字符串,但仍然出现此错误:

enter image description here

最佳答案

Workaround: Change a property on one of the two identical classes.

EF matches on class name AND class properties. So I just changed a property name on one of the EF objects, and the error is gone.

As @Entrodus commented on one of the other answers:

EF collision happens only when two classes have the same name AND the same set of parameters.

The mapping of CLR type to EDM type is ambiguous with EF 6 & 5?

关于c# - 项目包含多个 EDMX 文件时抛出 "the entity type is not part of the model for the current context"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48011690/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com