Welcome to the Entity Framework tutorial (Code First). We have created simple tutorials from beginners to professionals to learn all the features & concepts of the Entity Framework Code First in C#. This tutorial is for those who
This entity framework tutorial requires a working knowledge of the following
- Visual Studio 2013/ Visual Studio 2015
- MS SQL Server.
Table of Content
- What is Entity Framework
- Table of Content
- Entity Framework Resources
What is Entity Framework
The Microsoft Entity Framework is an ORM Framework. The Entity framework sits between your application and the data store. The applications use the Entity framework API for the database related operations. The Entity Framework maps all the database related operations to the database
Entity Framework is an open-source framework for Microsoft. You can find the Entity Framework project on the CodePlex.
Table of Content
Introduction to Entity Framework
- Introduction to Entity Framework
This Tutorial Covers the Brief Introduction and concepts behind the entity framework.
- Getting Started with Entity Framework
This tutorial discusses the various building blocks of the Microsoft Entity Framework. It also looks at the various terms used in the entity framework and its architecture. The Various Entity Data model like Conceptual, storage & mapping layers are covered here.
- Introduction to Entity Framework Code First
This chapter introduces you to Code First and advantageous of Code First against other models like database first/model first
- Code First Example
This tutorial guides you through creating a simple Console application using the Code First Concepts. The Console application creates a Simple user model and shows you how to perform a simple CRUD operation on the user model.
- ASP.NET MVC Code First Approach
This Entity Framework Tutorial guides you through creating the simple ASP.NET MVC Application using the Code First model.
Connecting to Database
- Database Connection
Learn about how the entity framework discovers and create a database based on the convention.
- Database Initialization
This tutorial we will look at how to initialize the database using the in-built initializers provided by the entity framework
- Custom Database Initializer in Entity Framework
Here we look at how to create the custom database initializer
Seeding & Migrations
- Seed Database in Entity Framework
Here we look at how to pre-populate (Seed) the database with default data.
- Code First with an existing database
Learn how to use Code First with the existing database. You can connect to your existing database and reverse engineer the entity models from the database
Components of Entity Framework
- DBContext in Entity Framework.
The DbContext is often referred to as the context is the class. This class interacts with the entity model and the database. Using DBContext we can run queries against the database to perform CRUD operations.
- DBSet in Entity Framework
The DBContext class exposes the DBSet Class for each entity in the model. DBSet allows us to query the database using the IQueryable Interface. Learn about the Properties and methods of DBSet Class.
Configuring the Entity Framework
- Configure the 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 in three ways. Default Conventions, Configurations &
Custom Code Conventions. In this Tutorial and in subsequent tutorials, we take look at how to configure our database using these techniques
- Code First Conventions in Entity Framework
Learn about how the Entity framework Configures the database using the Conventions.
- Data Annotations in Entity Framework
This tutorial explains how to use the Data Annotations to configure the database schema. The Data annotations attribute helps Entity Framework Code First to apply certain rules on entity models. The following are the list of Data Annotation attributes available in the Entity Framework Code First
- Fluent API in Entity Framework
This Tutorial Gives a brief Introduction to Fluent API
- Configure Entity Mappings Using Fluent API
This Tutorial explains how to use Fluent API To Configure the Entities
- Configure Entity Properties Using Fluent API
This Tutorial explains how to use Fluent API To Configure the Properties of Entities
Relationships in Entity Framework
- Relationships in Entity Framework
Learn about how entity framework handles various relationships like one to one, one to many and many to many.
- One to one relationship in Entity Framework
Configuring the One to One relationship in Entity Framework
- One to Many relationships in Entity Framework
Configuring the One to Many relationships in Entity Framework
- Many to Many relationships in Entity Framework
Configuring the Many to Many relationships in Entity Framework
LINQ To Entities
- LINQ to Entities Tutorial in Entity Framework / Entity Framework Core
Learn LINQ to Entities in a simple and easy steps. Learn to Query, Add, update, delete records from the database using LINQ to entities in entity framework
- Querying LINQ to Entities in EF & EF Core
Learn how to Write a simple query, which retrieves the collection of data from the table. how to filter the data with where clause. How to Sort the output using the orderBy method.
- Finding the Single Entity using Find, First, FirstOrDefault, Single, SingleOrDefault in EF / EF Core
Learn how to return a Single entity from the table using Primary Key. Learn how to return the results from the database using the other fields using the methods like First, FirstOrDefault, Single, SingleOrDefault etc.
- Projection Queries in Entity Framework EF & EF Core
Projection queries in Entity Framework are used to create a query that selects from a set of entities in your model but returns results that are of a different type. Find out how to return an Annonymous or Custom Type from the LINQ To Entities Queries
- Join Queries in Entity Framework & EF Core
Learn to use Join Queries to Load Data from multiple tables using both query & Method syntax
- Loading Related Data in EF
Find out how to retrieve Related data from the Entities using Navigation Properties.
- Lazy Loading in Entity Framework
Lazy loading is the process where the Entity Framework delays the loading of an entity or collection of entities until the time application actually needs it.
- Eager Loading in Entity Framework
Eager loading is a process where related entities are loaded along with the target entity
- Explicit Loading in Entity Framework
Explicit Loading is a process where related entities are loaded with an explicit call. it works very similar to Lazy Loading, but the loading of the related entities happens only after an explicit call
Persisting the Data
- Persistence in Entity Framework
Learn how entity framework handles persistence
- EntityStates in Entity Framework
The Entity Framework Persists the Entities to the database by keeping track of State of Entities. Entity Framework keeps track of, whether entities in memory are in sync with their corresponding rows in the database.
- Adding New Entities in Entity Framework
- Update Record in Entity Framework
- Deleting Records in Entity Framework
- Logging database operations Entity Framework
Entity Framework allows us to log the commands & queries sent to the database. The Logging is done by using the DbContext.Database.Log property, which can be set to a delegate for any method that takes a string. In this tutorial, we will look into how to implement the database log in Entity Framework
- Best Entity Framework Books