当前位置:Gxlcms > 
数据库问题 > 
《MVC+EF》——用DBFirst创建ADO.NET实体数据模型和对象关系映射
                     
                    
                        《MVC+EF》——用DBFirst创建ADO.NET实体数据模型和对象关系映射
                        
                            时间:2021-07-01 10:21:17
                            帮助过:58人阅读
							                        
                     
                    
                    
                    
         <Key>  
           <PropertyRef Name="Id" />  
         </Key>  
         <Property Name="Id" Type="int" StoreGeneratedPattern="Identity" Nullable="false" />  
         <Property Name="Author" Type="int" Nullable="false" />  
         <Property Name="Name" Type="nvarchar" MaxLength="50" Nullable="false" />  
         <Property Name="Remark" Type="nvarchar" MaxLength="200" />  
         <Property Name="Statu" Type="int" Nullable="false" />  
         <Property Name="IsDel" Type="bit" Nullable="false" />  
         <Property Name="Addtime" Type="datetime" Nullable="false" />  
       </EntityType>  
     Csharp中BlogArticleCate实体类的数据
 
- <EntityType Name="BlogArticleCate">  
-        <Key>  
-          <PropertyRef Name="Id" />  
-        </Key>  
-        <Property Name="Id" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />  
-        <Property Name="Author" Type="Int32" Nullable="false" />  
-        <Property Name="Name" Type="String" MaxLength="50" FixedLength="false" Unicode="true" Nullable="false" />  
-        <Property Name="Remark" Type="String" MaxLength="200" FixedLength="false" Unicode="true" />  
-        <Property Name="Statu" Type="Int32" Nullable="false" />  
-        <Property Name="IsDel" Type="Boolean" Nullable="false" />  
-        <Property Name="Addtime" Type="DateTime" Nullable="false" Precision="3" />  
-        <NavigationProperty Name="BlogArticles" Relationship="Self.FK_BlogArticle_BlogArticleCate" FromRole="BlogArticleCate" ToRole="BlogArticle" />  
-        <NavigationProperty Name="BlogUser" Relationship="Self.FK_BlogArticleCate_BlogUser" FromRole="BlogArticleCate" ToRole="BlogUser" />  
-      </EntityType>  
      数据库中的表与实体之间的对应关系   
 
- <EntitySetMapping Name="BlogArticleCates">  
-            <EntityTypeMapping TypeName="OumindBlogModel.BlogArticleCate">  
-              <MappingFragment StoreEntitySet="BlogArticleCate">  
-                <ScalarProperty Name="Id" ColumnName="Id" />  
-                <ScalarProperty Name="Author" ColumnName="Author" />  
-                <ScalarProperty Name="Name" ColumnName="Name" />  
-                <ScalarProperty Name="Remark" ColumnName="Remark" />  
-                <ScalarProperty Name="Statu" ColumnName="Statu" />  
-                <ScalarProperty Name="IsDel" ColumnName="IsDel" />  
-                <ScalarProperty Name="Addtime" ColumnName="Addtime" />  
-              </MappingFragment>  
-            </EntityTypeMapping>  
-          </EntitySetMapping>  
       
 
    看看上面的对应的关系,一个实体类中的属性相对应着数据库表中的一个字段,还有他们分别在C#类中、表中各自的数据类型。正是有了上面的一一对应关系,我才明白:当我们用EF操作实体类中的数据的时候,EF为什么能将实体中“属性”的数据映射到表中的“字段”里面去的。
  
 
《MVC+EF》——用DBFirst创建ADO.NET实体数据模型和对象关系映射
标签:点击   正是   text   自己   pat   http   article   文件的   bsp