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; }
}
}

1.ef 映射关系的更多相关文章

  1. EF里的继承映射关系TPH、TPT和TPC的讲解以及一些具体的例子

    本章节讲解EF里的继承映射关系,分为TPH.TPT.TPC.具体: 1.TPH:Table Per Hierarchy 这是EF的默认的继承映射关系:一张表存放基类和子类的所有列,自动生成的discr ...

  2. EF——继承映射关系TPH、TPT和TPC的讲解以及一些具体的例子 05 (转)

    EF里的继承映射关系TPH.TPT和TPC的讲解以及一些具体的例子   本章节讲解EF里的继承映射关系,分为TPH.TPT.TPC.具体: 1.TPH:Table Per Hierarchy 这是EF ...

  3. EF中关系映射问题

    一对一,和一对多的简单问题就部说了,直接来多对多这样的问题吧. 首现关系映射为这样的: /// <summary> /// 对应数据库中dbo.Address表 /// </summ ...

  4. Repository模式--采用EF Fluent API使用EntityTypeConfiguration分文件配置Model映射关系

    EF中类EntityTypeConfiguration是一个很有用的类,在nopCommerence中就使用这个类来分文件分文件配置Model映射关系.今天我就来谈谈Repository模式在Enti ...

  5. C# 数据操作系列 - 6 EF Core 配置映射关系

    0. 前言 在<C# 数据操作系列 - 5. EF Core 入门>篇中,我们简单的通过两个类演示了一下EF增删改查等功能.细心的小伙伴可能看了生成的DDL SQL 语句,在里面发现了些端 ...

  6. entity framework里的继承映射关系TPH、TPT和TPC

    本章节讲解EF里的继承映射关系,分为TPH.TPT.TPC.具体: 1.TPH:Table Per Hierarchy 这是EF的默认的继承映射关系:一张表存放基类和子类的所有列,自动生成的discr ...

  7. EntityFramework Core映射关系详解

    前言 Hello,开始回归开始每周更新一到两篇博客,本节我们回归下EF Core基础,来讲述EF Core中到底是如何映射的,废话少说,我们开始. One-Many Relationship(一对多关 ...

  8. 802.1p 优先级与内部优先级的映射关系

    缺省情况下,所有华为 S 系列交换机的 802.1P 优先级 与内部优先级的映射关系是 一 样的,如表 10-3 所示.从中可以看出,这些交换机中 802.1p 优先级与内部优先级的缺省映射关系是按等 ...

  9. 补知识:EntityFramework Core映射关系详解

    前言 本节我们回归下EF Core基础,来讲述EF Core中到底是如何映射的,废话少说,我们开始. One-Many Relationship(一对多关系) 首先我们从最简单的一对多关系说起,我们给 ...

随机推荐

  1. etcd服务端和客户端安装

    下载地址: 服务端:http://download.csdn.net/download/wuxun1997/9841277 客户端:http://download.csdn.net/download/ ...

  2. Linux I2C设备驱动

    i2c设备:ts.camera.audio.gsensor.e2prom I2C基本协议: 写:开始 -> 设备地址 -> 写标志 -> 应答 -> 内部地址 -> 应答 ...

  3. HTTP API 设计指南

    本指南描述了一系列 HTTP+JSON API 的设计实践, 来自并展开于 Heroku Platform API 的工作.本指南指导着Heroku内部API的开发,我们希望也能对Heroku以外的A ...

  4. Nginx安装过程

    1. 首先 ./configure --prefix=/usr/common/nginx --with-http_stub_status_module 报如下错误: 2. 从报的错可以看出缺少pcre ...

  5. 蓝桥杯 算法训练 ALGO-108 最大的体积

    算法训练 最大体积   时间限制:1.0s   内存限制:256.0MB 问题描述 每个物品有一定的体积(废话),不同的物品组合,装入背包会战用一定的总体积.假如每个物品有无限件可用,那么有些体积是永 ...

  6. Redhat下 Apache, php, mysql的默认安装路径

    apache: 如果采用RPM包安装,安装路径应在 /etc/httpd目录下 apache配置文件:/etc/httpd/conf/httpd.conf Apache模块路径:/usr/sbin/a ...

  7. 批处理判断是否有.net环境

    @echo off (echo 已安装.NET Framework) else (echo 未安装.NET Framework) pause>nul

  8. 反射getattr,hasattr,setattr,delattr

    通过字符串映射或修改程序运行时的状态.属性.方法, 有以下4个方法 getattr(object, name_str, default=None) 根据字符串name_str去获取obj对象里的方法内 ...

  9. 列举不少于6条的IE与FF脚本兼容性问题,需要写出命令

    (1) window.event: 表示当前的事件对象,IE有这个对象,FF没有,FF通过给事件处理函数传递事件对象 (2) 获取事件源 IE用srcElement获取事件源,而FF用target获取 ...

  10. java-虚拟机-索引

    底层 JVM之堆内存(年经代,老年代) Java内存泄露的理解与解决 内存溢出和内存泄漏的区别.产生原因以及解决方案 JVM内容梳理 Jvm的体系结构