This presentation starts on with the basics of code-first and then moves on to configure one-to-one, one-to-many and many-to-many relationship with Data Annotation as well as Fluent API.
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
Getting Started with EF6 Code First and MVC
1. Getting Started with EF6, Code First
and MVC
Presenter: Tanveer Singh, Mindfire Solutions
2. Topic
1. Entity Framework CF First Approach
2. Basics of Code First
3. Fluent Api
4. Data Annotations
5. Migrations
3. What is Code First ?
Code First development with Entity Framework 6.0
New approaches to modeling for Entity Framework 6.0.
1. Model First
2. Code First
3. Database first
4. Approaches
Model First -
Using the Model First approach a developer can start working with the model of the database and
creating entities which make logical sense irrelevant of how they will actually be stored in the
database in terms of tables.
5. Approaches
Code First -
The Code first approach is the most recent approach provided by Microsoft as part of the Entity
Framework 4.0. Its a more developer oriented approach where a developer can literally code the
entities required within the system as if they were regular classes and objects and then create the
database schema from these classes by defining special relationships and mappings within these
entities.
The main advantages in utilizing the Code First approach is that the developer has complete
control on the relations between the entities Using the code first approach the developer can also
provide restrictions and annotations on specific properties in the domain models (classes) which
will serve as validations both on the database and also within the code itself.
6. Approaches
Database First -
The Database First Approach
provides an alternative to
the Code First and Model
First approaches to the
Entity Data Model and it
creates model codes
(classes, properties,
DbContext etc.) from the
database in the project and
those classes become the
link between the database
and controller
7. One important thing to understand is that there are -
Two new types introduced for Code First approach
DbContext and DbSet.
DbContext is a simplified alternative to ObjectContext and is the primary object for interacting with a
database using a specific model.
DbSet(Of TEntity) is a simplified alternative to ObjectSet(Of TEntity) and is used to perform CRUD
operations against a specific type from the model in Code First approach.