Code First Conventions


What are Code First Conventions in Entity Framework?

The Code First Conventions enable the description of a model by using C# or VB .NET classes. The basic shape of the model is detected by using conventions. The Conventions are a set of rules used to configure a conceptual model automatically based on class definitions when working with Code First. The conventions are defined in the System.Data.Entity.ModelCongifuration.Conventions namespace.

An overview of conventions used by Code First is:

  • Type Discovery - When the Code uses first development, write the net framework classes, and it defines your conceptual (domain) model. In addition to defining classes, you need to be allowed to know which kind of type. This establishes a context section derived from DB Context of the style you want to be part of the model. Although the Code first defined these types of these types in the form of referenced kind of reference. If the classes attend a right to a right, a DB set property is enough to define a DB set property; the results are automatically included as a basic class.
  • Primary Set Convention - If the Code is named a primary key in a class, a primary key is called "ID" or not sensitive to a class (not case sensitive) or the class name.
  • Relationship Convention - In the entity framework, navigation properties provide the relationship between the two entity types. All things will have a navigation property for all things to participate. Navigation properties Allow you and provide a reference object (if multiplied) or a collection of a collection) or a group (if multiplied). Navigation properties are allowed to you (if multiples) are many (if multiples)—first favorable relationships based on navigation properties designated in your types.

    In addition to the Navigation properties, we recommend including a foreign key to represent depending on dependent objects. A Name of the same data type in the same data type for the main primary key property: ' Name> ', or' '. If multiple matches are found, and prioritized in the order listed above, the foreign key finding is not case sensitive. When a foreign key detects the property, the Code is first based on the nullability of the foreign key. If the property is temporary, the connection is optionally registered; or has been reported as needed.

    If a foreign key in the dependent institution is not invalid, the Code is set to find the cascade first. If a foreign key in the dependent institution is invalid, the Code has not deleted the relationship, and the foreign key will be invalid when the principal eliminates the principal.
  • Complex Type Convention - When the Code is first detected, a primary key is not inferred to a class definition, is not registered with an elementary-type discovery requirement, and not mention any other types of entity. Enter the following class the definition code first, and the details will be assumed because the details are not a primary key.
  • Removing Conventions - To remove any of the conventions defined in the System.Data.Entity.ModelConfiguration.Conventions namespace.
3