Entity Framework Code-First(10.1):EntityTypeConfiguration
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的更多相关文章
- Entity Framework Code first(转载)
一.Entity Framework Code first(代码优先)使用过程 1.1Entity Framework 代码优先简介 不得不提Entity Framework Code First这个 ...
- 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的无状态模 ...
- Entity Framework Code First (三)Data Annotations
Entity Framework Code First 利用一种被称为约定(Conventions)优于配置(Configuration)的编程模式允许你使用自己的 domain classes 来表 ...
- Entity Framework Code First (二)Custom Conventions
---------------------------------------------------------------------------------------------------- ...
- Entity Framework Code First (一)Conventions
Entity Framework 简言之就是一个ORM(Object-Relational Mapper)框架. Code First 使得你能够通过C#的类来描述一个模型,模型如何被发现/检测就是通 ...
- Entity Framework Code First (七)空间数据类型 Spatial Data Types
声明:本文针对 EF5+, Visual Studio 2012+ 空间数据类型(Spatial Data Types)是在 EF5 中引入的,空间数据类型表现有两种: Geography (地理学上 ...
- Entity Framework Code First (四)Fluent API - 配置属性/类型
上篇博文说过当我们定义的类不能遵循约定(Conventions)的时候,Code First 提供了两种方式来配置你的类:DataAnnotations 和 Fluent API, 本文将关注 Flu ...
- Entity Framework Code First (八)迁移 Migrations
创建初始模型和数据库 在开始使用迁移(Migrations)之前,我们需要一个 Project 和一个 Code First Model, 对于本文将使用典型的 Blog 和 Post 模型 创建一个 ...
- Entity Framework Code First (六)存储过程
声明:本文只针对 EF6+ 默认情况下,Code First 对实体进行插入.更新.删除操作是直接在表上进行的,从 EF6 开始你可以选择使用存储过程(Stored Procedures) 简单实体映 ...
随机推荐
- Python 3 常用模块之 一
Python 3 模块 一. time模块 时间模块 在Python中,通常有这几种方式来表示时间: 1.1 时间戳(timestamp): 通常来说,时间戳表示的是从1970年1月1日00:00: ...
- while & do-while
while的形式——while(条件表达式){循环体:} 当满足条件表达式时,执行循环体,之后继续验证是否满足条件表达式,满足继续执行循环体,之后重复,直到不满足条件表达式,循环结束. 先判断, ...
- vim配置文件 .vimrc 重要参数
vim配置文件的路径为 ~/.vimrc 重要参数如下: set mouse=a //激活鼠标可用 syntax enable //开启语法 set cursorline //开启当前行光标线 ...
- Wildfly在Linux下以Service的方式启动 配置步骤
1.前提介绍 在目前项目中使用Wildfly9在linux下部署项目,经常会通过远程的SSH来启动关闭服务.但是通过SHH启动 standalone.sh 的服务,如果关闭窗口服务就会被停掉.所以就想 ...
- 1.微信小程序-B站:前言准备
前言 <微信小程序开发-B站>是以bilibili移动端网站为基础开发微信小程序版本,笔者喜欢的学习是愉快.轻松并能学到实战的东西,不知各位观友有没有一样的经历,就是一有问题不是先去Goo ...
- 囤题&&发布记录
声明 && 温馨提示 by ljh2000 听说有人很喜欢狙我......看我不把你们抓起来嘿嘿嘿! 为了采取措施,不让被狙成为生活常态(雾 ,我要闭关锁国辣,我要开始(屯田)囤题 ...
- Codeforces Round #250 (Div. 2) A, B, C
A. The Child and Homework time limit per test 1 second memory limit per test 256 megabytes input sta ...
- Android Studio 技巧备忘
1.日志输入匹配 在日志输入框,点击Edit Filter Configuration 输入syso,并匹配规则 这样就过滤出自己想要的日志
- C#--父子页面传值、刷新(showModalDialog)
父页面: var obj = new Object(); obj.name="name"; var rtnValue=window.showModalDialog("ch ...
- linux-常用指令1
掌握下面的命令是最基本的噢!那是我们使用一个系统最基本的操作. 玩过dos么,其实,linux下的文件操作和dos差不多.没什么难的,多练习就记住了.下面如果有条件的话请跟我一样操作吧!百看不如一做. ...