EF Core Part-I(Asp.Net Core)

Banushan Puviraj
3 min readMar 28, 2021

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.

1) Code-First.

2) Database-First.

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.

  1. DbContext & DbSet
  2. Data Model
  3. Querying using Linq-to-Entities
  4. Change Tracking
  5. SaveChanges
  6. Migrations

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.

  1. EDMX/ Graphical Visualization of Model
  2. Entity Data Model Wizard (for DB-First approach)
  3. ObjectContext API
  4. Querying using Entity SQL.
  5. Automated Migration
  6. Inheritance: Table per type (TPT)
  7. Inheritance: Table per concrete class (TPC)
  8. Many-to-Many without join entity
  9. Entity Splitting
  10. Spatial Data
  11. Lazy loading of related data
  12. Stored procedure mapping with DbContext for CUD operation
  13. Seed data
  14. Automatic migration

EF Core includes the following new features which are not supported in EF6.

  1. Easy relationship configuration
  2. Batch INSERT, UPDATE and DELETE operations
  3. In-memory provider for testing
  4. Support for IoC (Inversion of Control)
  5. Unique constraints
  6. Shadow properties
  7. Alternate keys
  8. Global query filter
  9. Field mapping
  10. DbContext pooling
  11. Better patterns for handling disconnected entity graphs.

Below NuGetPackages are important to start EF Core. You should install everything depends on your need.

  1. Microsoft.EntityFrameworkCore
  2. Microsoft.EntityFrameworkCore.SqlServer
  3. Microsoft.EntityFrameworkCore.Tools
  4. System.ComponentModel.Annotations

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.

Conclusion

This Article We have discussed EF Core, EF6, and EF Core Installation. Next Chapter We will learn about EF6 Features With C# examples.

--

--

Banushan Puviraj

The very basic core of a man’s living spirit is his passion for adventure