标签:
1.edmx
<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="3.0" xmlns:edmx="http://schemas.microsoft.com/ado/2009/11/edmx">
<!-- EF Runtime content -->
<edmx:Runtime>
<!-- SSDL content -->
<edmx:StorageModels>
<Schema Namespace="Model1.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/11/edm/ssdl">
<EntityContainer Name="Model1StoreContainer">
<EntitySet Name="Classes" EntityType="Model1.Store.Classes" store:Type="Tables" Schema="dbo" />
<EntitySet Name="Students" EntityType="Model1.Store.Students" store:Type="Tables" Schema="dbo" />
<AssociationSet Name="ClassStudent" Association="Model1.Store.ClassStudent">
<End Role="Class" EntitySet="Classes" />
<End Role="Student" EntitySet="Students" />
</AssociationSet>
</EntityContainer>
<EntityType Name="Classes">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="Id" Type="int" StoreGeneratedPattern="Identity" Nullable="false" />
<Property Name="ClassName" Type="nvarchar(max)" Nullable="false" />
<Property Name="ClassNo" Type="nvarchar(max)" Nullable="false" />
<Property Name="DeptNo" Type="nvarchar(max)" Nullable="false" />
</EntityType>
<EntityType Name="Students">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="Id" Type="int" StoreGeneratedPattern="Identity" Nullable="false" />
<Property Name="Name" Type="nvarchar(max)" Nullable="false" />
<Property Name="Address" Type="nvarchar(max)" Nullable="false" />
<Property Name="ClassId" Type="int" Nullable="false" />
</EntityType>
<Association Name="ClassStudent">
<End Role="Class" Type="Model1.Store.Classes" Multiplicity="1" />
<End Role="Student" Type="Model1.Store.Students" Multiplicity="*" />
<ReferentialConstraint>
<Principal Role="Class">
<PropertyRef Name="Id" />
</Principal>
<Dependent Role="Student">
<PropertyRef Name="ClassId" />
</Dependent>
</ReferentialConstraint>
</Association>
</Schema></edmx:StorageModels>
<!-- CSDL content -->
<edmx:ConceptualModels>
<Schema xmlns="http://schemas.microsoft.com/ado/2009/11/edm" xmlns:cg="http://schemas.microsoft.com/ado/2006/04/codegeneration" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" Namespace="Model1" Alias="Self" xmlns:annotation="http://schemas.microsoft.com/ado/2009/02/edm/annotation" annotation:UseStrongSpatialTypes="false">
<EntityContainer Name="Model1Container" annotation:LazyLoadingEnabled="true">
<EntitySet Name="Classes2" EntityType="Model1.Class2" />
<EntitySet Name="Students2" EntityType="Model1.Student2" />
<AssociationSet Name="ClassStudent" Association="Model1.ClassStudent">
<End Role="Class" EntitySet="Classes2" />
<End Role="Student" EntitySet="Students2" />
</AssociationSet>
</EntityContainer>
<EntityType Name="Class2">
<Key>
<PropertyRef Name="Id2" />
</Key>
<Property Name="Id2" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
<Property Name="ClassName2" Type="String" Nullable="false" />
<Property Name="ClassNo2" Type="String" Nullable="false" />
<Property Name="DeptNo2" Type="String" Nullable="false" />
<NavigationProperty Name="DaoStudent" Relationship="Model1.ClassStudent" FromRole="Class" ToRole="Student" />
</EntityType>
<EntityType Name="Student2">
<Key>
<PropertyRef Name="Id2" />
</Key>
<Property Name="Id2" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
<Property Name="StuName2" Type="String" Nullable="false" />
<Property Name="Address2" Type="String" Nullable="false" />
<NavigationProperty Name="DaoClass" Relationship="Model1.ClassStudent" FromRole="Student" ToRole="Class" />
<Property Name="ClassId" Type="Int32" Nullable="false" />
</EntityType>
<Association Name="ClassStudent">
<End Type="Model1.Class2" Role="Class" Multiplicity="1" />
<End Type="Model1.Student2" Role="Student" Multiplicity="*" />
<ReferentialConstraint>
<Principal Role="Class">
<PropertyRef Name="Id2" />
</Principal>
<Dependent Role="Student">
<PropertyRef Name="ClassId" />
</Dependent>
</ReferentialConstraint>
</Association>
</Schema>
</edmx:ConceptualModels>
<!-- C-S mapping content -->
<edmx:Mappings>
<Mapping Space="C-S" xmlns="http://schemas.microsoft.com/ado/2009/11/mapping/cs">
<EntityContainerMapping StorageEntityContainer="Model1StoreContainer" CdmEntityContainer="Model1Container">
<EntitySetMapping Name="Classes2">
<EntityTypeMapping TypeName="IsTypeOf(Model1.Class2)">
<MappingFragment StoreEntitySet="Classes">
<ScalarProperty Name="Id2" ColumnName="Id" />
<ScalarProperty Name="ClassName2" ColumnName="ClassName" />
<ScalarProperty Name="ClassNo2" ColumnName="ClassNo" />
<ScalarProperty Name="DeptNo2" ColumnName="DeptNo" />
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>
<EntitySetMapping Name="Students2">
<EntityTypeMapping TypeName="IsTypeOf(Model1.Student2)">
<MappingFragment StoreEntitySet="Students">
<ScalarProperty Name="Id2" ColumnName="Id" />
<ScalarProperty Name="StuName2" ColumnName="Name" />
<ScalarProperty Name="Address2" ColumnName="Address" />
<ScalarProperty Name="ClassId" ColumnName="ClassId" />
</MappingFragment>
</EntityTypeMapping>
</EntitySetMapping>
</EntityContainerMapping>
</Mapping></edmx:Mappings>
</edmx:Runtime>
<!-- EF Designer content (DO NOT EDIT MANUALLY BELOW HERE) -->
<edmx:Designer xmlns="http://schemas.microsoft.com/ado/2009/11/edmx">
<edmx:Connection>
<DesignerInfoPropertySet>
<DesignerProperty Name="MetadataArtifactProcessing" Value="EmbedInOutputAssembly" />
</DesignerInfoPropertySet>
</edmx:Connection>
<edmx:Options>
<DesignerInfoPropertySet>
<DesignerProperty Name="ValidateOnBuild" Value="true" />
<DesignerProperty Name="EnablePluralization" Value="False" />
<DesignerProperty Name="CodeGenerationStrategy" Value="无" />
<DesignerProperty Name="UseLegacyProvider" Value="False" />
</DesignerInfoPropertySet>
</edmx:Options>
<!-- Diagram content (shape and connector positions) -->
<edmx:Diagrams>
</edmx:Diagrams>
</edmx:Designer>
</edmx:Edmx>
2.上下文
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码已从模板生成。
//
// 手动更改此文件可能导致应用程序出现意外的行为。
// 如果重新生成代码,将覆盖对此文件的手动更改。
// </auto-generated>
//------------------------------------------------------------------------------
namespace Model
{
using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
public partial class Model1Container : DbContext
{
public Model1Container()
: base("name=Model1Container")
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public virtual DbSet<Class2> Classes2 { get; set; }
public virtual DbSet<Student2> Students2 { get; set; }
}
}
3.类文件
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码已从模板生成。
//
// 手动更改此文件可能导致应用程序出现意外的行为。
// 如果重新生成代码,将覆盖对此文件的手动更改。
// </auto-generated>
//------------------------------------------------------------------------------
namespace Model
{
using System;
using System.Collections.Generic;
public partial class Class2
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public Class2()
{
this.DaoStudent = new HashSet<Student2>();
}
public int Id2 { get; set; }
public string ClassName2 { get; set; }
public string ClassNo2 { get; set; }
public string DeptNo2 { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Student2> DaoStudent { get; set; }
}
}
类文件2
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码已从模板生成。
//
// 手动更改此文件可能导致应用程序出现意外的行为。
// 如果重新生成代码,将覆盖对此文件的手动更改。
// </auto-generated>
//------------------------------------------------------------------------------
namespace Model
{
using System;
using System.Collections.Generic;
public partial class Student2
{
public int Id2 { get; set; }
public string StuName2 { get; set; }
public string Address2 { get; set; }
public int ClassId { get; set; }
public virtual Class2 DaoClass { get; set; }
}
}
标签:
原文地址:http://www.cnblogs.com/kexb/p/4805649.html