码迷,mamicode.com
首页 > 其他好文 > 详细

Entity Framework Code-First(10.1):EntityTypeConfiguration

时间:2016-07-05 16:59:02      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:

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 NameReturn TypeDescription
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

标签:

原文地址:http://www.cnblogs.com/purplefox2008/p/5644234.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!