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

EntityTypeConfiguration has the following important methods:

Method NameReturn TypeDescription
HasKey<TKey>EntityTypeConfigurationConfigures the primary key property(s) for this entity type.
HasMany<TTargetEntity>ManyNavigationPropertyConfigurationConfigures a many-to-many relationship from this entity type.
HasOptional<TTargetEntity>OptionalNavigationPropertyConfigurationConfigures 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>RequiredNavigationPropertyConfigurationConfigures 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>VoidExcludes a property from the model so that it will not be mapped to the database.
MapEntityTypeConfigurationAllows advanced configuration related to how this entity type is mapped to the database schema.
Property<T>StructuralTypeConfigurationConfigures a struct property that is defined on this type.
ToTableVoidConfigures 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.

转载于:https://www.cnblogs.com/purplefox2008/p/5644234.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值