EntityTypeConfiguration Class in Code-First:

Before we start to configure using Fluent API, let's see an important class of Fluent API.

EntityTypeConfiguration is an important class in Fluent API. EntityTypeConfiguration provides you important methods to configure entities and its properties to override various Code-First conventions. It can be obtained by calling the Entity<TEntity>() method of DbModelBuilder class as shown below.

EntityTypeConfiguration has the following important methods:

Method Name Return Type Description
HasKey<TKey> EntityTypeConfiguration Configures the primary key property(s) for this entity type.
HasMany<TTargetEntity> ManyNavigationPropertyConfiguration Configures a many-to-many relationship from this entity type.
HasOptional<TTargetEntity> OptionalNavigationPropertyConfiguration Configures an optional relationship from this entity type. Instances of the entity type can be saved to the database without this relationship being specified. The foreign key in the database will be nullable.
HasRequired<TTargetEntity> RequiredNavigationPropertyConfiguration Configures a required relationship from this entity type. Instances of the entity type will not be able to be saved to the database unless this relationship is specified. The foreign key in the database will be non-nullable.
Ignore<TProperty> Void Excludes a property from the model so that it will not be mapped to the database.
Map EntityTypeConfiguration Allows advanced configuration related to how this entity type is mapped to the database schema.
Property<T> StructuralTypeConfiguration Configures a struct property that is defined on this type.
ToTable Void Configures the table name that this entity type is mapped to.

Visit MSDN for more information on EntityTypeConfiguration class.

Let's start to configure entities using Fluent API in the next section.

Entity Framework Code-First(10.1):EntityTypeConfiguration的更多相关文章

  1. Entity Framework Code first(转载)

    一.Entity Framework Code first(代码优先)使用过程 1.1Entity Framework 代码优先简介 不得不提Entity Framework Code First这个 ...

  2. ASP.NET MVC深入浅出系列(持续更新) ORM系列之Entity FrameWork详解(持续更新) 第十六节:语法总结(3)(C#6.0和C#7.0新语法) 第三节:深度剖析各类数据结构(Array、List、Queue、Stack)及线程安全问题和yeild关键字 各种通讯连接方式 设计模式篇 第十二节: 总结Quartz.Net几种部署模式(IIS、Exe、服务部署【借

    ASP.NET MVC深入浅出系列(持续更新)   一. ASP.NET体系 从事.Net开发以来,最先接触的Web开发框架是Asp.Net WebForm,该框架高度封装,为了隐藏Http的无状态模 ...

  3. Entity Framework Code First (三)Data Annotations

    Entity Framework Code First 利用一种被称为约定(Conventions)优于配置(Configuration)的编程模式允许你使用自己的 domain classes 来表 ...

  4. Entity Framework Code First (二)Custom Conventions

    ---------------------------------------------------------------------------------------------------- ...

  5. Entity Framework Code First (一)Conventions

    Entity Framework 简言之就是一个ORM(Object-Relational Mapper)框架. Code First 使得你能够通过C#的类来描述一个模型,模型如何被发现/检测就是通 ...

  6. Entity Framework Code First (七)空间数据类型 Spatial Data Types

    声明:本文针对 EF5+, Visual Studio 2012+ 空间数据类型(Spatial Data Types)是在 EF5 中引入的,空间数据类型表现有两种: Geography (地理学上 ...

  7. Entity Framework Code First (四)Fluent API - 配置属性/类型

    上篇博文说过当我们定义的类不能遵循约定(Conventions)的时候,Code First 提供了两种方式来配置你的类:DataAnnotations 和 Fluent API, 本文将关注 Flu ...

  8. Entity Framework Code First (八)迁移 Migrations

    创建初始模型和数据库 在开始使用迁移(Migrations)之前,我们需要一个 Project 和一个 Code First Model, 对于本文将使用典型的 Blog 和 Post 模型 创建一个 ...

  9. Entity Framework Code First (六)存储过程

    声明:本文只针对 EF6+ 默认情况下,Code First 对实体进行插入.更新.删除操作是直接在表上进行的,从 EF6 开始你可以选择使用存储过程(Stored Procedures) 简单实体映 ...

随机推荐

  1. 一看就懂的数据库范式介绍(1NF,2NF,3NF,BC NF,4NF,5NF)

    原文:http://josh-persistence.iteye.com/blog/2200644 一.基本介绍 设计关系数据库时,遵从不同的规范要求,设计出合理的关系型数据库,这些不同的规范要求被称 ...

  2. HDU 2736 Surprising Strings

                                    Surprising Strings Time Limit:1000MS     Memory Limit:65536KB     64 ...

  3. mysql日志总结

    1.mysql慢查询设置 log-slow-queries=/alidata/mysql-log/mysql-slow.loglong_query_time = 1log-queries-not-us ...

  4. 更改ubuntu主机名称

    vim /etc/hostname 将root更改为admin vim /etc/passwd

  5. CSS3按钮效果制作

    CSS3按钮效果制作 首先附上效果图,按下去有一种下沉的效果, 未按效果 按下去效果 原理:第一个按钮相对比较简单,就直接是一个双重阴影效果,然后鼠标按下去让他的margin-top值为-3px,阴影 ...

  6. Confluence 6 找到未使用的空间

    有时候,你希望找到你系统中没有使用的内容.有时候你也希望能够对这些内容进行更多的关注,但是如何找到一些有关长期不更新的页面,或者长期不使用的空间? View Space Activity 页面中的内容 ...

  7. node.js+express+jade系列三:404错误的配置

    1:新建一个404.jade 2:在app.js后面配置如下代码 app.use(function(req, res){        res.render("404", {sta ...

  8. Hibernate 原汁原味的四种抓取策略(转)

    原文出处:http://www.cnblogs.com/rongxh7/archive/2010/05/12/1733088.html     尊重原作者,访问原创地址 最近在研究 Hibernate ...

  9. 原生js监听input值改变事件

    哈哈哈,又来了,今天闲来无事,实验了下原生js监听input value值改变事件,下面就来说道说道: 本来写监听input值便获是用jquery的,之前的随笔写了,就是这个方法,地址:http:// ...

  10. java中变量的分类

    •按被声明的位置划分: –成员变量:方法外部.类的内部定义的变量 –局部变量:方法或语句块内部定义的变量        –注意:类外面(类对应的大括号外面)不能有变量的声明 •按所属的数据类型划分: ...