What is Code First (EF Code First series), codeef
Code First is supported in EF4.1. This method is very useful in domain design patterns. With the Code First mode, you can focus on Domain Design and create a class set for your objects in a domain as needed, instead of designing the database First, and then designing your class based on the database, code-First APis will create a database for you based on your class and configuration.
As a developer, you first write C # Or VB.. NET class and context class. When you run the program, Code-First ApIs will create a database (if this database does not exist), and then use the default conventions, map your class to the database. Of course, you can configure your domain class to override the default convention and map the database. Here you can use the data Annotation Feature and Fluent API.
The basic workflow is:
First, write the domain class and context class ---> Configure the ing conditions for the domain class -----> click F5 to run the program ----> Code -- First APIs to create a new database, you can also map the domain class to an existing database ----> set to add the test data to the database ----> finally run the program.
In the next section, let's look at a simple Code-First example.
Attached series directory:
- What is Code First?
- Simple Code First example
- Code-First Convention
- DB Initialization (Database Initialization)
- Inheritance Strategy (Inheritance Policy)
- Configure Domain Classes (configuration Domain class)
- DataAnnotations (Data annotation)
- Fluent API
- Configure One-to-One (Configure a One-to-One relationship)
- Configure One-to-multiple (Configure One-to-multiple relationships)
- Configure allow-to-Configure (Configure Many-to-Many relationships)
- Move deployments (data migration)
- DB Initialization Strategy (Database Initialization Policy)