EntityFramework 6 RC1 Include on Many-to-Many property fails(EntityFramework 6 RC1 包含在多对多属性上失败)
问题描述
代理和代理组之间存在多对多关系(伪代码,缩写).
I have a many-to-many relationship between Agents and AgentGroups (psuedocode, abbreviated).
public class Agent {
public virtual List<AgentGroup> AgentGroups { get; set; }
}
public class AgentGroup {
public virtual List<Agent> Agents { get; set; }
}
在代码中的某个时刻,我想获取所有 AgentGroups,并且我想预取/包含每个组的 Agents.我也想在代理上预填充 AgentGroups 集合.这在 EF 6 beta 中有效,但在 EF 6 rc1 中不再有效:
At some point in the code, I want to get all AgentGroups, and I want to prefetch/include the Agents for each group. I also want to pre-fill the AgentGroups collection on the Agents. This was working in EF 6 beta, but no longer works in EF 6 rc1:
List<AgentGroup> allGroups = context.AgentGroups.Include("Agents").Include("Agents.AgentGroups").ToList();
我得到的错误信息是
对象名称dbo.AgentAgentGroups"无效.
Invalid object name 'dbo.AgentAgentGroups'.
而实际上并没有AgentAgentGroups
表,表是dbo.AgentGroupAgents
.关于让它再次工作的任何想法?
And in fact, there isn't a table AgentAgentGroups
, the table is dbo.AgentGroupAgents
. Any ideas on getting this to work again?
我目前没有注释,也没有使用 fluent API,这完全是默认的代码优先约定.
I currently have no annotations and am not using the fluent API, it's all strictly the default code first conventions.
推荐答案
在 rc1 中,多对多关联中联结表的命名约定似乎发生了变化.当我在各种 EF 版本中尝试您的模型时,我看到的是:
In rc1 there appears to be a change in naming convention of the junction table in many-to-many associations. When I try your model in various EF versions, this is what I see:
- EF5(稳定):
AgentGroupAgents
- EF6(测试版):
AgentGroupAgents
- EF6 (rc1):
AgentAgentGroups
如果 beta 版本不同也不错,但 rc1 与上一个 RTM 版本不同,这使得这是一个突破性的变化.好收获!
It wouldn't be bad if the beta was different, but rc1 differs from the last RTM version, which makes this a breaking change. Good catch!
编辑
EF 团队的回答:
你好,
在 EF6 之前,模型创建的某些领域是不确定的 - 根据您是在 x86 还是 x64 上运行,您可以获得不同的模型.多对多连接表名就是这些领域之一.在 EF6 中,我们解决了这个问题,以确保结果始终相同.不幸的是,这确实意味着对于某些模型(取决于它们运行的架构)升级到 EF6 可能会导致模型更改.但是现在计算的模型将在机器和未来版本的 EF 中保持一致.如果您想继续使用原来的名称,最好的选择是使用 Fluent API指定连接表名称.
~罗文
Hello,
Prior to EF6 there were some areas of model creation that were non-deterministic - depending on whether you were running on x86 or x64 you could get a different model. The many to many join table name was one of these areas. In EF6 we addressed this to ensure the results would always be the same. Unfortunately, that does mean that for some models (depending on which architecture they were running on) upgrading to EF6 can cause a model change. But the model that is now calculated will be consistent across machines and future versions of EF. If you want to continue using the original name, the best option is to use the Fluent API to specify the join table name.
~Rowan
这篇关于EntityFramework 6 RC1 包含在多对多属性上失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:EntityFramework 6 RC1 包含在多对多属性上失败
基础教程推荐
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- c# Math.Sqrt 实现 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01