我有两个表:地址和联系它们连接上的ContactID(在联系)。这两个表在我的实体数据模型实体(EF 4.0),我不wan't对其进行修改。
I have two tables: Address and Contact which are joined on contactID (in Contact). Both of these tables have entities in my Entity data model (EF 4.0) and I do not wan't to modify them.
我想创建一个包含两个实体的信息的新实体。
I do want to create a new entity that contains information from both entities.
我所做的,到目前为止:
What I did so far:
在CSDL:
<EntityContainer...>
<EntitySet Name="AddressTest" EntityType="WebGearsModel.Test" />
<EntitySet Name="ContactTest" EntityType="WebGearsModel.Test" />
</EntityContainer>
<EntityType Name="Test">
<Key>
<PropertyRef Name="addressID" />
</Key>
<Property Type="Int32" Name="addressID" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
<Property Type="Int32" Name="contactID" Nullable="false" />
<Property Type="String" Name="firstName" Nullable="false" MaxLength="30" FixedLength="false" Unicode="false" />
<Property Type="String" Name="emailAddress" Nullable="false" MaxLength="150" FixedLength="false" Unicode="false" />
</EntityType>
在我的C-S映射:
<EntitySetMapping Name="AddressTest">
<EntityTypeMapping TypeName="WebGearsModel.Test">
<MappingFragment StoreEntitySet="Address">
<ScalarProperty Name="addressID" ColumnName="addressID" />
<ScalarProperty Name="contactID" ColumnName="contactID" />
<ScalarProperty Name="firstName" ColumnName="firstName" />
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>
<EntitySetMapping Name="ContactTest">
<EntityTypeMapping TypeName="WebGearsModel.Test">
<MappingFragment StoreEntitySet="Contact">
<ScalarProperty Name="contactID" ColumnName="contactID" />
<ScalarProperty Name="emailAddress" ColumnName="emailAddress" />
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>
我收到的错误是:
The error I'm receiving is:
在映射碎片问题开始 在行150:必须为指定映射 所有关键特性 的(ContactTest.addressID) EntitySet的ContactTest。
Problem in mapping fragments starting at line 150:Must specify mapping for all key properties (ContactTest.addressID) of the EntitySet ContactTest.
我怎么映射从联系人实体的AddressID时,它不会在该实体存在吗?我想我需要某种关联,但我不知道该如何去做......请记住,我不希望有改变我现有的地址和联系的实体。
How am I supposed to map an AddressID from the Contact entity when it doesn't exist in that entity? I guess I need some sort of association but I'm unsure how to go about it... Remember, I don't want to have to modify my existing Address and Contact entities.
记住一个实体的定义:
这是不被定义的一个对象的 属性,而是由一个线程 连续性和其身份。
An object that is not defined by its attributes, but rather by a thread of continuity and its identity.
每一个实体必须拥有的东西,唯一标识;关键。但是,你似乎是试图从只有一个按键,它提供了地址的一致认同,但不接触单个物理类型定义了两种类型的实体。这违反了实体的规则,使得ContactTest概念无效。
Every "entity" must have something that uniquely identifies it; a key. However, you appear to be trying to define two types of entities from a single physical type that has only one key that provides a consistent identity for addresses, but not contacts. That violates the rules of an Entity, making the ContactTest concept invalid.
由于底层物理类型,测试
,定义了一个关键属性, addressID
,所有的EntitySet的该类型派生必须映射该属性,以符合定义的实体规则。维护状态的一致性是不可能的,否则。
Since the underlying physical type, Test
, defines a key property, addressID
, all EntitySet's derived from that type must map that property to conform to the rules defining an Entity. Maintaining consistency of state is impossible otherwise.