与beta 2的EDM映射问题 [英] EDM mapping problem with beta 2

查看:110
本文介绍了与beta 2的EDM映射问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有四张桌子Child,Toy,Food和Child2Entity。我希望通过关联表将孩子,糖果(1对多)和玩具(1对多)联系起来。
所有玩具的EntityType = 1,糖果的EntityType = 2。来自DB的孩子我希望根据EntityType获得他所有相关的糖果和玩具,例如,如果我选择从EntityType = 1中检索孩子和他的相关实体,我将期望得到一个特定的孩子玩具。
我也希望有可能在DB中保存一个孩子和一个相关实体(玩具或糖果)。
请注意Child和Child2Entity之间只有一个关联。儿童2实体代码片段:

< EntityType Name =" Child2Entity"> 
< Key>
< PropertyRef Name =" ChildID" />
< PropertyRef Name =" EntityID" />
< PropertyRef Name =" EntityTypeID" />
< / Key>
< Property Name =" ChildID"类型=" INT"可空= QUOT假QUOT; />
< Property Name =" EntityID"类型=" INT"可空= QUOT假QUOT; />
< Property Name =" EntityTypeID"类型=" INT"可空= QUOT假QUOT; />
< / EntityType>


儿童代码段:

< EntityType Name = "儿童"> 
< Key>
< PropertyRef Name =" ID" />
< / Key>
< Property Name =" ID"类型=" INT"可空= QUOT假QUOT; />
< Property Name =" Name"类型=" nvarchar的"的MaxLength = QUOT; 50" />
< Property Name =" Address"类型="为nvarchar(最大)" />
< / EntityType>


玩具代码段:

< EntityType Name =" Toy"> 
< Key>
< PropertyRef Name =" ID" />
< / Key>
< Property Name =" ID"类型=" INT"可空= QUOT假QUOT; />
< Property Name =" Name"类型=" nvarchar的"的MaxLength = QUOT; 50" />
< / EntityType>


糖果代码段:

< EntityType Name =" Candy" > 
< Key>
< PropertyRef Name =" ID" />
< / Key>
< Property Name =" ID"类型=" INT"可空= QUOT假QUOT; />
< Property Name =" Name"类型=" nvarchar的"的MaxLength = QUOT; 50" />
< Property Name =" Color"类型=" INT" />
< / EntityType>


Child和Child2Entity之间的关联:

< Association Name =" FK_Child2Entity_Child"> ; 
< End Role =" Child"类型=" AppBlockTestModel.Store.Child"多重= QUOT 1 QUOT; />
< End Role =" Child2Entity"类型=" AppBlockTestModel.Store.Child2Entity"多重= QUOT * QUOT; />
< ReferentialConstraint>
< Principal Role =" Child">
< PropertyRef Name =" ID" />
< / Principal>
< Dependent Role =" Child2Entity">
< PropertyRef Name =" ChildID" />
< / Dependent>
< / ReferentialConstraint>
< / Association>

解决方案

嗨majhul,

我正在移动这个帖子到EF预发布论坛,因为有更多关于beta2的专家。
你会在那个论坛得到更好的答案。

最诚挚的问候是刘志春

I have four tables Child, Toy, Food and Child2Entity. I want to associate to a child, candies (1 to many) and toys (1 to many) by the association table.
All the toys have EntityType=1 and Candies have EntityType=2.
When Getting a child from DB I want to get all his related candies and toys according to the EntityType
for instance if i choose to retrieve a child and his related Entities from EntityType=1 i will expect to get a certain child with all his toys.
I also wish to have the possibility to save in DB a child and a related entity (a toy or a candy).
Please pay attention that there is only one association between Child and  Child2Entity.

 
Child2Entity code snippet:

<EntityType Name="Child2Entity">
          <Key>
            <PropertyRef Name="ChildID" />
            <PropertyRef Name="EntityID" />
            <PropertyRef Name="EntityTypeID" />
          </Key>
          <Property Name="ChildID" Type="int" Nullable="false" />
          <Property Name="EntityID" Type="int" Nullable="false" />
          <Property Name="EntityTypeID" Type="int" Nullable="false" />
        </EntityType>


Child code snippet:

<EntityType Name="Child">
          <Key>
            <PropertyRef Name="ID" />
          </Key>
          <Property Name="ID" Type="int" Nullable="false" />
          <Property Name="Name" Type="nvarchar" MaxLength="50" />
          <Property Name="Address" Type="nvarchar(max)" />
        </EntityType>

Toy code snippet:

<EntityType Name="Toy">
          <Key>
            <PropertyRef Name="ID" />
          </Key>
          <Property Name="ID" Type="int" Nullable="false" />
          <Property Name="Name" Type="nvarchar" MaxLength="50" />
</EntityType>

Candy code snippet:

<EntityType Name="Candy">
          <Key>
            <PropertyRef Name="ID" />
          </Key>
          <Property Name="ID" Type="int" Nullable="false" />
          <Property Name="Name" Type="nvarchar" MaxLength="50" />
          <Property Name="Color" Type="int" />
        </EntityType>

Association between Child and Child2Entity:

<Association Name="FK_Child2Entity_Child">
          <End Role="Child" Type="AppBlockTestModel.Store.Child" Multiplicity="1" />
          <End Role="Child2Entity" Type="AppBlockTestModel.Store.Child2Entity" Multiplicity="*" />
          <ReferentialConstraint>
            <Principal Role="Child">
              <PropertyRef Name="ID" />
            </Principal>
            <Dependent Role="Child2Entity">
              <PropertyRef Name="ChildID" />
            </Dependent>
          </ReferentialConstraint>
        </Association>

解决方案

Hi majhul,

I'm moving this thread to EF pre-release forum, since there are more experts on beta2.
You'll get better answer in that forum.


Best Regards
Yichun Feng


这篇关于与beta 2的EDM映射问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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