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. LOJ10042 收集雪花

    题意 不同的雪花往往有不同的形状.在北方的同学想将雪花收集起来,作为礼物送给在南方的同学们.一共有 n 个时刻,给出每个时刻下落雪花的形状,用不同的整数表示不同的形状.在收集的过程中,同学们不希望有重 ...

  2. IPv6与IPv4最主要的不同

    IP第6个版本(IPv6),是互联网协议的新版本,设计为IP第4版本(IPv4,RFC-791)的继任.从IPv4升级到IPv6主要的改变有以下几类: 扩展地址容量 IPv6将IP地址的位址从32位提 ...

  3. [翻译]Web开发牛人访谈:你们都在用什么?

    小肥鱼译注:早上看到这篇文章,觉得内容甚是有趣.作者跟web开发方面的诸多大牛进行了交流,了解到他们的研究动向,从访谈中可以看到各种风格的开发者,有浏览器控,有设备控.我想,知道行业里的优秀成员在做些 ...

  4. Linux修复磁盘操作

    Linux修复磁盘操作 1.卸载分区 umount /data 修复磁盘,先判读是磁盘坏了,还是文件系统坏了:一般可以修复,但是建议换磁盘. 2.fsck  -y /dev/sda1  ##-y 参数 ...

  5. php小白和菜鸟 上班路上可以看的修行博客

    上班地铁 公交上我们不要去追剧 不要去打游戏 不要看看有效性的海量新闻, 我们需要去技术博客里遨游, 下面就推荐点与php有关的可以学习的技术博客; 大部分程序员在自学的道路上不知道走了多少坑,这个视 ...

  6. 【转】JMeter基础之——一个简单的性能测试

    上一节中,我们了解了jmeter的一此主要元件,那么这些元件如何使用到性能测试中呢.这一节创建一个简单的测试计划来使用这些元件.该计划对应的测试需求. 1)测试目标网站是fnng.cnblogs.co ...

  7. Linux学习笔记 -- Shell 变量

    定义变量 语法: 变量名=值 myVal= 需要注意一下变量明德规则: 首个字符必须为字母(a-z,A-Z). 中间不能有空格,可以使用下划线(_). 不能使用标点符号. 不能使用bash里的关键字( ...

  8. Javascript 推荐一个图形化展示库

    觉得这个库不错: http://almende.github.io/chap-links-library/index.html

  9. JS中有几种数据类型分别是哪几种

    number,string,boolean,null,undefined,object

  10. Python多线程-队列

    队列就是存东西取东西,多用于多线程中 按照顺序 对传入的数据按规定的顺序输出 # -*- coding:utf-8 -*- __author__ = "MuT6 Sch01aR" ...