EDM mapping problem with beta 2
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" />Candy code snippet:
</EntityType>
<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>- Moved byYichun_FengMSFTSunday, November 08, 2009 2:40 AMBeta2 questions (From:ADO.NET Entity Framework and LINQ to Entities)
All Replies
- 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
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
ConditionalAssociations are not supported by EF so you won't be able to define this in your model. I think one way to do this is to create an entity that maps 1:1 with Child2Entity table and use Linq or ESql to get the information you want. You would also need to add some validation in the business logic to make sure that the EntityTypeId is correctly being set based on the type that the Child2Entity is being associated with.
Thanks
Srikanth
This posting is provided "AS IS" with no warranties, and confers no rights.- Proposed As Answer byDiego B VegaMSFT, ModeratorSaturday, November 21, 2009 8:31 AM


