该篇学习了实体模型相关知识:
(一)实体模型得组成:
(1)概念模型:用概念架构定义语言(CSDL)Conceptual schema definition language表示。
(2)存储模型:用存储架构定义语言(SSDL)Store schema definition language 表示(3)映射信息:用映射规范语言 (MSL)
(二)以员工部门实体为列讲解。
(1)实体示例:截图
(2)对添加的*.edmx,右键打开方式,选择,可以看到如下截图:
(3)其三种模型得XML代码:
代码
<? xml version="1.0" encoding="utf-8" ?> < edmx:Edmx Version ="2.0" xmlns:edmx ="http://schemas.microsoft.com/ado/2008/10/edmx" > <!-- EF Runtime content --> < edmx:Runtime > <!-- SSDL content --> < edmx:StorageModels > < Schema Namespace ="MyDBModel.Store" Alias ="Self" Provider ="System.Data.SqlClient" ProviderManifestToken ="2008" xmlns:store ="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns ="http://schemas.microsoft.com/ado/2009/02/edm/ssdl" > < EntityContainer Name ="MyDBModelStoreContainer" > < EntitySet Name ="Department" EntityType ="MyDBModel.Store.Department" store:Type ="Tables" Schema ="dbo" /> < EntitySet Name ="Employee" EntityType ="MyDBModel.Store.Employee" store:Type ="Tables" Schema ="dbo" /> < AssociationSet Name ="FK_Employee_Department" Association ="MyDBModel.Store.FK_Employee_Department" > < End Role ="Department" EntitySet ="Department" /> < End Role ="Employee" EntitySet ="Employee" /> </ AssociationSet > </ EntityContainer > < EntityType Name ="Department" > < Key > < PropertyRef Name ="DepartmentID" /> </ Key > < Property Name ="DepartmentID" Type ="int" Nullable ="false" StoreGeneratedPattern ="Identity" /> < Property Name ="DepartmentName" Type ="nvarchar" Nullable ="false" MaxLength ="50" /> </ EntityType > < EntityType Name ="Employee" > < Key > < PropertyRef Name ="EmployeeID" /> </ Key > < Property Name ="EmployeeID" Type ="int" Nullable ="false" StoreGeneratedPattern ="Identity" /> < Property Name ="EmployeeName" Type ="nvarchar" Nullable ="false" MaxLength ="50" /> < Property Name ="DepartmentID" Type ="int" Nullable ="false" /> </ EntityType > < Association Name ="FK_Employee_Department" > < End Role ="Department" Type ="MyDBModel.Store.Department" Multiplicity ="1" /> < End Role ="Employee" Type ="MyDBModel.Store.Employee" Multiplicity ="*" /> < ReferentialConstraint > < Principal Role ="Department" > < PropertyRef Name ="DepartmentID" /> </ Principal > < Dependent Role ="Employee" > < PropertyRef Name ="DepartmentID" /> </ Dependent > </ ReferentialConstraint > </ Association > </ Schema > </ edmx:StorageModels > <!-- CSDL content --> < edmx:ConceptualModels > < Schema Namespace ="MyDBModel" Alias ="Self" xmlns:annotation ="http://schemas.microsoft.com/ado/2009/02/edm/annotation" xmlns ="http://schemas.microsoft.com/ado/2008/09/edm" > < EntityContainer Name ="MyDBEntities" annotation:LazyLoadingEnabled ="true" > < EntitySet Name ="Departments" EntityType ="MyDBModel.Department" /> < EntitySet Name ="Employees" EntityType ="MyDBModel.Employee" /> < AssociationSet Name ="FK_Employee_Department" Association ="MyDBModel.FK_Employee_Department" > < End Role ="Department" EntitySet ="Departments" /> < End Role ="Employee" EntitySet ="Employees" /> </ AssociationSet > </ EntityContainer > < EntityType Name ="Department" > < Key > < PropertyRef Name ="DepartmentID" /> </ Key > < Property Name ="DepartmentID" Type ="Int32" Nullable ="false" annotation:StoreGeneratedPattern ="Identity" /> < Property Name ="DepartmentName" Type ="String" Nullable ="false" MaxLength ="50" Unicode ="true" FixedLength ="false" /> < NavigationProperty Name ="Employees" Relationship ="MyDBModel.FK_Employee_Department" FromRole ="Department" ToRole ="Employee" /> </ EntityType > < EntityType Name ="Employee" > < Key > < PropertyRef Name ="EmployeeID" /> </ Key > < Property Name ="EmployeeID" Type ="Int32" Nullable ="false" annotation:StoreGeneratedPattern ="Identity" /> < Property Name ="EmployeeName" Type ="String" Nullable ="false" MaxLength ="50" Unicode ="true" FixedLength ="false" /> < Property Name ="DepartmentID" Type ="Int32" Nullable ="false" /> < NavigationProperty Name ="Department" Relationship ="MyDBModel.FK_Employee_Department" FromRole ="Employee" ToRole ="Department" /> </ EntityType > < Association Name ="FK_Employee_Department" > < End Role ="Department" Type ="MyDBModel.Department" Multiplicity ="1" /> < End Role ="Employee" Type ="MyDBModel.Employee" Multiplicity ="*" /> < ReferentialConstraint > < Principal Role ="Department" > < PropertyRef Name ="DepartmentID" /> </ Principal > < Dependent Role ="Employee" > < PropertyRef Name ="DepartmentID" /> </ Dependent > </ ReferentialConstraint > </ Association > </ Schema > </ edmx:ConceptualModels > <!-- C-S mapping content --> < edmx:Mappings > < Mapping Space ="C-S" xmlns ="http://schemas.microsoft.com/ado/2008/09/mapping/cs" > < EntityContainerMapping StorageEntityContainer ="MyDBModelStoreContainer" CdmEntityContainer ="MyDBEntities" > < EntitySetMapping Name ="Departments" >< EntityTypeMapping TypeName ="MyDBModel.Department" >< MappingFragment StoreEntitySet ="Department" > < ScalarProperty Name ="DepartmentID" ColumnName ="DepartmentID" /> < ScalarProperty Name ="DepartmentName" ColumnName ="DepartmentName" /> </ MappingFragment ></ EntityTypeMapping ></ EntitySetMapping > < EntitySetMapping Name ="Employees" >< EntityTypeMapping TypeName ="MyDBModel.Employee" >< MappingFragment StoreEntitySet ="Employee" > < ScalarProperty Name ="EmployeeID" ColumnName ="EmployeeID" /> < ScalarProperty Name ="EmployeeName" ColumnName ="EmployeeName" /> < ScalarProperty Name ="DepartmentID" ColumnName ="DepartmentID" /> </ MappingFragment ></ EntityTypeMapping ></ EntitySetMapping > </ EntityContainerMapping > </ Mapping > </ edmx:Mappings > </ edmx:Runtime > <!-- EF Designer content (DO NOT EDIT MANUALLY BELOW HERE) --> < Designer xmlns ="http://schemas.microsoft.com/ado/2008/10/edmx" > < Connection > < DesignerInfoPropertySet > < DesignerProperty Name ="MetadataArtifactProcessing" Value ="EmbedInOutputAssembly" /> </ DesignerInfoPropertySet > </ Connection > < Options > < DesignerInfoPropertySet > < DesignerProperty Name ="ValidateOnBuild" Value ="true" /> < DesignerProperty Name ="EnablePluralization" Value ="False" /> < DesignerProperty Name ="IncludeForeignKeysInModel" Value ="True" /> </ DesignerInfoPropertySet > </ Options > <!-- Diagram content (shape and connector positions) --> < Diagrams > < Diagram Name ="Model1" > < EntityTypeShape EntityType ="MyDBModel.Department" Width ="1.5" PointX ="0.75" PointY ="1" Height ="1.45359375" IsExpanded ="true" /> < EntityTypeShape EntityType ="MyDBModel.Employee" Width ="1.5" PointX ="3" PointY ="0.875" Height ="1.6222135416666674" IsExpanded ="true" /> < AssociationConnector Association ="MyDBModel.FK_Employee_Department" ManuallyRouted ="false" > < ConnectorPoint PointX ="2.25" PointY ="1.726796875" /> < ConnectorPoint PointX ="3" PointY ="1.726796875" /> </ AssociationConnector > </ Diagram > </ Diagrams > </ Designer > </ edmx:Edmx >
(三)*.edmx中的Designer.
(1)截图:
(2)MyDBEntities : ObjectContext。并且重写了数据库连接。