Craig Stuntz很好地解释了造成这里大部分问题的是与设计器相关的 xml(实体和关联等在设计表面上的位置)。然而,元素内的冲突解决 edmx:Runtime
是非常容易实现的。
处理与设计器相关的 xml 中的冲突的最佳策略是通过牺牲任何自定义布局并恢复为默认布局来完全绕过它们。
诀窍是删除<Diagrams>
元素的所有内容。设计器将毫无问题地打开并应用默认布局。
以下是将以默认布局打开的 EDMX 文件示例。请注意,<edmx:Runtime>
元素的内容也被删除了,但这只是为了简洁起见 - 它不是解决方案的一部分。
<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="2.0" xmlns:edmx="http://schemas.microsoft.com/ado/2008/10/edmx">
<!-- EF Runtime content -->
<edmx:Runtime>
<!-- Removed for brevity's sake only!-->
</edmx:Runtime>
<!-- EF Designer content (DO NOT EDIT MANUALLY BELOW HERE) -->
<Designer xmlns="http://schemas.microsoft.com/ado/2008/10/edmx">
<Connection>
<DesignerInfoPropertySet>
<DesignerProperty Name="MetadataArtifactProcessing" Value="EmbedInOutputAssembly" />
</DesignerInfoPropertySet>
</Connection>
<Options>
<DesignerInfoPropertySet>
<DesignerProperty Name="ValidateOnBuild" Value="true" />
<DesignerProperty Name="EnablePluralization" Value="True" />
<DesignerProperty Name="IncludeForeignKeysInModel" Value="True" />
</DesignerInfoPropertySet>
</Options>
<!-- Diagram content (shape and connector positions) -->
<Diagrams>
</Diagrams>
</Designer>
</edmx:Edmx>
请注意,此处应用的默认布局与您从设计器的上下文菜单中选择时的结果不匹配,Diagram | Layout Diagram
这是我所期望的。
更新:从Entity Framework 5开始,这变得更容易了。在那里添加的多图表支持将与图表相关的 xml 卸载到单独的文件中。请注意,我在 edmx 文件中仍然有一些与图表相关的旧标签,这些标签已经经历了多次实体框架升级。我只是从 edmx 文件中删除了名为 Diagrams(包括子项)的标签。