Configure Entity Data Model

In the Getting Started tutorial we showed you how to create the Simple domain class in C#. The Entity Framework (EF) automatically translated the properties to the columns in the table and created the database.

Configure Entity Data Model

The table is not only about columns. We need to specify the data types, the length of each column, Primary Key, Foreign Key ETC. In EF this can be achieved by three ways

  1. Default Conventions
  2. Configurations
  3. Custom Code Conventions

Default Conventions

The Entity framework makes certain assumptions based on your code before creating the database. This is known as the code First Conventions. This helps to reduce the amount of code you have to write. With the help of the conventions, the EF Decides what tables to create, which field to be used as Primary Key etc.

You can read about Code first Conventions from this Tutorial


EF allows us to fine tune the table schema using the configurations. The configuration overrides the Code first conventions. You can configure the domain classes and EF in two ways

  1. Data Annotations
    These are attributes applied directly to the classes and class properties. These attributes are available in the System.ComponentModel.DataAnnotations namespace.You can read it from this tutorial  Data Annotations in Entity Framework
  2. Fluent API
    The Fluent API is another way to configure our domain classes. It is more flexible and provides developers with more power to configure the database. You can read it from the tutorial Fluent API tutorial

Custom Code Conventions

The default Conventions are not sufficient to allow you to describe all properties of the column/table. Hence the Entity Framework from the Version 6 introduced the custom Code Convention. This allows you to create the defaults for individual entities.


In the next tutorial, we will look how setup the default convention in Entity Framework

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top