将单个实体映射到多个表 [英] map a single entity to multiple tables

查看:85
本文介绍了将单个实体映射到多个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的问题。如果我有1个实体映射到2个DB表。每个表都有一个外键列。

Here is my question. If I have 1 entity map to 2 DB tables. Each of this table has a foreign key column.

是否可以在这些外键上创建关联?

Is it possible to create association on these foreign keys?

这是标签< edmx:ConceptualModels>

This is in tag <edmx:ConceptualModels>

< EntityType < font color ="#0000ff"size = 2> 名称 = < font size = 2>" table1 " >

<EntityType Name="table1">

< >

<Key>

< PropertyRef 名称 = " ID " />

<PropertyRef Name="ID" />

< / Key >

</Key>

< 属性 名称 = " ID " 类型 = " < font color ="#0000ff"size = 2> Int64 " Nullable = " false " />

<Property Name="ID" Type="Int64" Nullable="false" />

< 属性 名称 = " column1 " 类型 = " Int64 " Nullable = " false " />

<Property Name="column1" Type="Int64" Nullable="false" />

/ *以下列来自第二个表格* /

< Property 名称 = " column2 " Type = " Int64 " Nullable = " false " /> / *这是表2的外键* /

<Property Name="column2" Type="Int64" Nullable="false" /> /*this is the foreign key to Table 2*/

< Property 名称 = " column3 " < font color ="#0000ff"size = 2> Type = < font color ="#000000"size = 2>" Int64 " Nullable = " false " ; />

<Property Name="column3" Type="Int64" Nullable="false" />

< NavigationProperty 名称 = " Table2 " 关系 = " Model.FK_Table1_Table2 " FromRole = " 表1 " ToRole = " Table2 " />

<NavigationProperty Name="Table2" Relationship="Model.FK_Table1_Table2" FromRole="Table1" ToRole="Table2" />

< / EntityType >

</EntityType>

< EntityType 名称 = " 表2 " >

<EntityType Name="Table2">

< Key >

<Key>

< PropertyRef 名称 = " ID " />

<PropertyRef Name="ID" />

< ; / Key >

</Key>

< 属性 名称 = " ID " Type = " Int64 " Nullable = " ; false " />

<Property Name="ID" Type="Int64" Nullable="false" />

< 属性 < font color ="#ff0000"size = 2>名称 = " column1 " 键入 = " Int64 " Nullable = " false " />

<Property Name="column1" Type="Int64" Nullable="false" />

< 属性 名称 = " column2 " Type = " String " Nullable = " ; false " MaxLength = " 100 " Unicode = " false " FixedLength = " false " />

<Property Name="column2" Type="String" Nullable="false" MaxLength="100" Unicode="false" FixedLength="false" />

< 属性 姓名 = " column3 " T ype = " 布尔 " Nullable = " false " />

<Property Name="column3" Type="Boolean" Nullable="false" />

< NavigationProperty 名称 = " Table1 " 关系 = " Model.FK_Table1_Table2 " FromRole = " Table2 " ToRole = " Table1 " />

<NavigationProperty Name="Table1" Relationship="Model.FK_Table1_Table2" FromRole="Table2" ToRole="Table1" />

< / EntityType >

</EntityType>

这是在< edmx:Mappings >

< AssociationSetMapping 姓名 = " FK_Table1_Table2 " TypeName = " Model.FK_Table1_Table2 " " StoreEntitySet = " Table1 " >

<AssociationSetMapping Name="FK_Table1_Table2" TypeName="Model.FK_Table1_Table2" " StoreEntitySet="Table1" >

< EndProperty 名称 = " Table1 " >

<EndProperty Name="Table1">

< ScalarProperty 名称 = " ID " ColumnName = " ID " />< / EndProperty > ;

<ScalarProperty Name="ID" ColumnName="ID" /></EndProperty>

< EndProperty 名称 = " 表2 " >

<EndProperty Name="Table2">

< ScalarProperty 名称 = " ID " ; ColumnName = " column2 " />< / EndProperty >

<ScalarProperty Name="ID" ColumnName="column2" /></EndProperty>

抱怨Table1不知道column2是否存在。

错误1错误2010:列'column2'指定了a这个MSL的一部分在MetadataWorkspace中不存在。

Error 1 Error 2010: The Column 'column2' specified as part of this MSL does not exist in MetadataWorkspace.

任何帮助将不胜感激。

推荐答案


这篇关于将单个实体映射到多个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆