EF Core Part-I(Asp.Net Core)
Before we move into EF Core what is ORM(Object Relational Mapper)? Object-Relational Mapping (ORM) is a technique for converting data between relational databases and object-oriented programming languages. Most OOP Backend programming languages have their own ORM.ex: Java(Hibernate), Python(PonyORM), etc.
Entity Framework 6 (EF6) is a tried and tested object-relational mapper (ORM) for. NET.
Entity Framework Core is a modern object-database mapper for. NET. It enables .NET developers to work with a database using .NET objects and an automated mechanism for accessing & storing the data in the database. Let's Move on to EF Core.
EF Core supports two development approaches.
CodeFirst- Code-First approach, we mainly focus on the domain of your application and start creating classes for our domain entity rather than design our database first and then create the classes which match our database design. Code-First is mainly useful in Domain-Driven Design.
DatabaseFirst- It creates model codes (Classes, properties, DbContext, etc.) from the Existing database to the project, and those classes become the link between the database and controller. The model is stored in an EDMX file (.edmx extension) and can be viewed and edited in the Entity Framework Designer.
EF Core vs EF 6
Below features are common for EF Core and EF6.
- DbContext & DbSet
- Data Model
- Querying using Linq-to-Entities
- Change Tracking
EF Core is included most of the features of EF 6 but there are some features of EF 6 which are not supported in EF Core.
- EDMX/ Graphical Visualization of Model
- Entity Data Model Wizard (for DB-First approach)
- ObjectContext API
- Querying using Entity SQL.
- Automated Migration
- Inheritance: Table per type (TPT)
- Inheritance: Table per concrete class (TPC)
- Many-to-Many without join entity
- Entity Splitting
- Spatial Data
- Lazy loading of related data
- Stored procedure mapping with DbContext for CUD operation
- Seed data
- Automatic migration
EF Core includes the following new features which are not supported in EF6.
- Easy relationship configuration
- Batch INSERT, UPDATE and DELETE operations
- In-memory provider for testing
- Support for IoC (Inversion of Control)
- Unique constraints
- Shadow properties
- Alternate keys
- Global query filter
- Field mapping
- DbContext pooling
- Better patterns for handling disconnected entity graphs.
Below NuGetPackages are important to start EF Core. You should install everything depends on your need.
Install EF Core DB Provider
EF Core allows us to access databases from the provider model. There are different EF Core DB providers(Mysql,MariaDB,Db2,SqlLite,PostgreSQL etc.) available for the different databases. These providers are available as NuGet packages. First, we need to install the NuGet package for the provider of the database we want to access. Let's say if we want to access the MS SQL Server database, we should install Microsoft.EntityFrameworkCore.SqlServer NuGet package.
Install EF Core Tools
Along with the DB provider package, you need to install EF tools to execute EF Core commands. These make it easier to perform several EF Core-related tasks in your project, such as migrations, scaffolding, etc.
This Article We have discussed EF Core, EF6, and EF Core Installation. Next Chapter We will learn about EF6 Features With C# examples.