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) 简单实体映 ...
随机推荐
- File Space——一个java structs2.0的小栗子(DIY)
1 概述 File Space系统适用于团体,主要提供的是团队文件分享以及个人文件的存储管理服务.分为个人文件存储管理平台和团队文件共享平台. 个人文件存储平台主要为个人提供相关的文件分类存储服务:该 ...
- vim配置与使用
Vim 是一个上古神器,本篇文章主要持续总结使用 Vim 的过程中不得不了解的一些指令和注意事项,以及持续分享一个前端工作者不得不安装的一些插件,而关于 Vim 的简介,主题的选择,以及为何使用 vi ...
- Spring中ApplicationContext和beanfactory区别
BeanFacotry是spring中比较原始的Factory.如XMLBeanFactory就是一种典型的BeanFactory.原始的BeanFactory无法支持spring的许多插件,如AOP ...
- Spring Cloud之统一fallback接口
每个方法都配备一个fallback方法 不利于开发的 用类的方式 并且整个方法都是在同一个线程池里面的 主要对于client的修改: pom: <project xmlns="http ...
- mysqldump导出格式
#导出大表:mysqldump --add-drop-table --single-transaction --triggers -R -quick --disable-keys -utest -pt ...
- BZOJ 1597 [Usaco2008 Mar]土地购买:斜率优化dp
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1597 题意: 有n块矩形土地,长为a[i],宽为b[i]. FJ想要将这n块土地全部买下来 ...
- 十五 Django框架,缓存
由于Django是动态网站,所有每次请求均会去数据进行相应的操作,当程序访问量大时,耗时必然会更加明显,最简单解决方式是使用:缓存,缓存将一个某个views的返回值保存至内存或者memcache中,5 ...
- leetcode 204. Count Primes(线性筛素数)
Description: Count the number of prime numbers less than a non-negative number, n. 题解:就是线性筛素数的模板题. c ...
- cudnn 卷积例子
运行环境:linux cuda cudnn cudnn API:https://docs.nvidia.com/deeplearning/sdk/cudnn-developer-guide/index ...
- 【遍历二叉树】02二叉树的中序遍历【Binary Tree Inorder Traversal】
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 给定一个二叉树,返回他的中序遍历的 ...