Core--EDM Designer for the Entity Framework of the ". NET" EF Framework

Source: Internet
Author: User

preliminary understanding of the previous blogEF,is always sayingEDM, in the endWhat isEDM??Let's uncover the veil of mystery.:  XMLin those"mess"the Code.

EntityData Modelis the so-called Entity Data Model,alsoEDM.in theVSadded inADOEntity Data Model allows you to draw entities directly,up can be convenient for our development,map down directly to the database,Developer action entities do not need to understand the database table structure.here is. EDMXThe two entities in the,we don't have a database concept here.,but with a name calledDBContextthe context object that represents the collection of these entities.



EDMdesigners can design the above model,This model includes defining the entity,PRIMARY Key,Properties,Associate,Table,column,relationships and indexes, etc..actually, EDMThe essence is aXMLfile,Right-click the file to selectXMLEditor Open.such a file is so complicated that we're a little intimidated.,don't wait to turn it off .,hear me out..

EDM the three parts :

  1. CSDL - Conceptual Model , language files defined by the conceptual schema (. csdl) to define
  2. Storage Model , language files defined by the storage schema (. ssdl) to define
  3. Mapping , language files by mapping specification (. MSL) to define

Whole XML the files are collapsed as shown below. :




First, CSDLis the entity class,it defines the entities and relationships that are known to the business layer of the application, EntityTyperepresents an entity,EntitySet represents an entity set, Associationrepresenting Relationships, Keyrepresents a primary key, etc..This is one of the most fundamental components of object-oriented design.,it embodies the object design method which can be represented in the real world in the most kind of computation .The following code is a bit long, mainly to reflect the relationship between Userinfos and departments, which gives a scalar attribute of two entity sets, Navigation property is a navigation attribute.

<edmx:ConceptualModels> <schema namespace= "Highschoolbasetestmodel" alias= "self" p1:usestrongspatialtypes = "false" xmlns:annotation= "http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns:p1= "http// Schemas.microsoft.com/ado/2009/02/edm/annotation "xmlns=" http://schemas.microsoft.com/ado/2009/11/edm "> < EntityContainer name= "Highschoolbasetestmodelentities" p1:lazyloadingenabled= "true" > <entityset Name= "Depar Tments "entitytype=" highschoolbasetestmodelmodel.departments "/> <entityset Name=" UserInfos "Enti Tytype= "Highschoolbasetestmodelmodel.userinfos"/> <associationset name= "Departmentuserinfo" Association= "H            Ighschoolbasetestmodelmodel.departmentuserinfo "> <end role=" Departments "entityset=" Departments "/> <end role= "Userinfos" entityset= "Userinfos"/> </AssociationSet> </entitycontainer   > <entitytype name= "Departments" >       <Key> <propertyref name= "id"/> </Key> <property name= "id" type= " Int32 "nullable=" false "/> <property name=" Name "type=" String "nullable=" false "Maxlength=" "Unicode=" Tru E "fixedlength=" false "/> <navigationproperty name=" Userinfos "relationship=" HIGHSCHOOLBASETESTMODELMODEL.D Epartmentuserinfo "fromrole=" departments "torole=" Userinfos "/> </entitytype><entitytype Name=" UserInfo S "> <Key> <propertyref name=" ID "/> </Key> <property name=" I  D "type=" Int32 "nullable=" false "/> <property name=" UserName "type=" String "nullable=" false "Maxlength=" 32 " Unicode= "true" Fixedlength= "false"/> <property name= "UserPassword" type= "String" nullable= "false" Maxleng Th= "Max" unicode= "true" Fixedlength= "false"/> <navigationproperty name= "departments" relationship= "HighSch Oolbasetestmodelmodel.dePartmentuserinfo "fromrole=" Userinfos "torole=" departments "/> </EntityType> <association name=" Departmentuserinfo "> <end role=" Departments "type=" Highschoolbasetestmodelmodel.departments "Multiplicity=" * "/> <end role=" Userinfos "type=" Highschoolbasetestmodelmodel.userinfos "multiplicity=" * "/> &lt ;/association> </Schema></edmx:ConceptualModels>

then, SSDLdescribes the table,column,Relationship,concepts that exist in databases such as primary keys and indexes. EntityContainerbased on database naming,eachEntitySetall correspond to a tableAssociationSetrepresenting Relationships.conceptual models and logical models can be one-to-a-kind associations,but it doesn't have to be linked in a one-to-one way,this isEDMthe function,like,an entity in the conceptual model,This entity actually derives its data from multiple tables in the database.You can see for yourself.XMLfile,can read it all ..Speaking of this ,,error when importing a table without a primary key in the entity Class Designer,so far, let's make sure the database table has a primary key and then import it.. 

finally , MSL The main is the above CSDL with the SSDL the corresponding , include CSDL in the properties and SSDL The corresponding in the column .

StorageEntityContainerand theStoreEntitySet is the name in the store,CdmEntityContainer andTypeName are the names in the corresponding model respectively.This is a mapping between two layers of models,This mapping allows developers to write code for the conceptual model, i.e. manipulate entities,These instructions are mapped to the logical model..

<entitycontainermapping storageentitycontainer= "Highschollbasetestmodelmodelstorecontainer" Cdmentitycontainer= "Highschollbasetestmodelentities" >    <entitysetmapping name= "Departments" >      <entitytypemapping typename= "istypeof (highschollbasetestmodelmodel.departments)" >        <MappingFragment Storeentityset= "Departments" >          <scalarproperty name= "id" columnname= "id"/>          <scalarproperty Name= "name" columnname= "name"/>        </MappingFragment>      </EntityTypeMapping>    </ Entitysetmapping></entitycontainermapping>

After the code, we must have a certain understanding of the EDM, in fact, for the computer, the whole world is 0 and 1, then we see everything can be displayed through the code, so rich and easy to use the design behind is not the same is the most basic XML? Below is a graph to represent the core of the EDM :


relationship of the Entity Data Model



Core--EDM Designer for the Entity Framework of the ". NET" EF Framework

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.