Several tables to an entity map
are usually stored normalized data in a database. In the application you want but often work with the non-normalized data. Is the ADO.NET Entity Framework is the solution?
Yes and no is the answer. And to put it forward to take away, a mapping is possible from multiple tables to one entity, but only if they have a 1:1 relationship. That is, in most cases you will be better off if created in the database an appropriate view, this is mapped to the entity and the Update, Insert and Delete stored procedures to be solved.
But the solution. First, a model is created with the wizard, which contains all the tables.
The adjustments to the Conceptual Model (CSDL) are simple. On the desired attributes of the entity from the other tables are added. For example, here the entity Cars to the attribute value has been enhanced.
\u0026lt;xml: namespace prefix = edmx /> \u0026lt;edmx:conceptualmodels>
\u0026lt;schema xmlns = "http://schemas.microsoft.com/ado/2006/04/edm" alias = " Self "namespace =" Model ">
\u0026lt;entitycontainer name="Entities">
\u0026lt;entityset name="Cars" entitytype="Model2.Cars">
\u0026lt;/ entitycontainer>
\u0026lt;EntityType name="Cars">
<key>
<propertyref name="ID_Cars">
</key>
<property name="ID_Cars" nullable="false" type="Guid"></property>
<property name="Brand" type="String" maxlength="50"></property>
<property name="Model" type="String" maxlength="50"></property>
<property name="Value" type="String" maxlength="50"></property>
\u0026lt;/ EntityType>
\u0026lt;/ schema>
\u0026lt;/ edmx: conceptualmodels>
adjustments to the storage model (SSDL) are not necessary because of the database, which is represented by this model will not change.
by adjusting the mapping of the newly defined attributes on the entity now in the existing storage model mapped. This is achieved by adding an additional fragment mapping.
\u0026lt;edmx:mappings>
\u0026lt;Mapping xmlns="urn:schemas-microsoft-com:windows:storage:mapping:CS" space="CS">
<entitycontainermapping cdmentitycontainer="Entities" storageentitycontainer="dbo">
<entitysetmapping name="Cars">
<entitytypemapping typename="IsTypeOf(Model.Cars)">
<mappingfragment storeentityset="Cars">
<scalarproperty name="ID_Cars" columnname="ID_Cars">
<scalarproperty name="Brand" columnname="Brand">
<scalarproperty name="Model" columnname="Model">
</mappingfragment>
<mappingfragment storeentityset="Extensions">
\u0026lt;scalarproperty name="ID_Cars" columnname="ID_Extensions">
\u0026lt;scalarproperty name="value" columnname="Value">
\u0026lt;/ MappingFragment>
\u0026lt;/ EntityTypeMapping & # 062
\u0026lt;/ EntitySetMapping>
\u0026lt;/ EntityContainerMapping>
\u0026lt;/ mapping>
\u0026lt;/ edmx: mappings> Do not
code as needed and EntitySets AssociationSet are CSDL and the To delete mapping.
0 comments:
Post a Comment