博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Linq to Entity 学习笔记(一):实体模型的理解
阅读量:5985 次
发布时间:2019-06-20

本文共 6923 字,大约阅读时间需要 23 分钟。

 

 

 

        该篇学习了实体模型相关知识:

(一)实体模型得组成:

(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。并且重写了数据库连接。

 

转载地址:http://sjulx.baihongyu.com/

你可能感兴趣的文章
数据库同步热备方案(武汉某医院)
查看>>
vb.net制作简单的下拉菜单
查看>>
mockito_mock测试
查看>>
linux 下的postfix的搭建
查看>>
dwz_springmvc 使用maven管理jar包
查看>>
我的友情链接
查看>>
Content-type 的说明 ,即 HTTP请求头的类型有哪些?
查看>>
CISSP-CBK十大知识体系
查看>>
使用JMeter进行负载测试——终极指南
查看>>
装了Oracle 10g后输入sqlplus 后 出现"无法初始化Oracle调用界面;Oracle不能正常工作"...
查看>>
MYSQL的InnoDB Buffer Pool内部机制
查看>>
部署 dubbo + zookeeper
查看>>
sql重写后比较是否一致
查看>>
python模块pymysql
查看>>
IOS UIScrollView详解 & 图片缩放功能
查看>>
正确计算linux系统内存使用率
查看>>
CentOS7同步远程yum源到本地
查看>>
域名服务器配置文件 /etc/resolv.conf
查看>>
What is Keepalived ?
查看>>
.on()的学习心得
查看>>