Entity Framework Code-first (10.1): Entitytypeconfiguration

Source: Internet
Author: User

Entitytypeconfiguration Class in Code-first:

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

Entitytypeconfiguration is a important class in Fluent API. Entitytypeconfiguration provides important methods to configure entities and its properties to override various Code-f IRST 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 the this entity type.
Hasoptional<ttargetentity> Optionalnavigationpropertyconfiguration Configures an optional relationship from the 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 would be nullable.
Hasrequired<ttargetentity> Requirednavigationpropertyconfiguration Configures a required relationship from the this entity type. Instances of the entity type are not being able to being saved to the database unless this relationship is specified. The foreign key in the database would be non-nullable.
Ignore<tproperty> Void Excludes a property from the model so, it would 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, which is defined on the this type.
ToTable Void Configures the table name, the This entity type was 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.