In this tutorial you will learn how to work with new Entity Framework in .net core framework, Though most of the functionalities will remain same as earlier framework, but there are some interesting new features in EF .net Core.
To start working with Entity framework Core with any type of .Net Core application,
first you need to install Microsoft.EntityFrameworkCore
library from Nuget package manager, so right click on your project solution and then open nuget manager, search for any library you want to install, then from search result select the library and install it.
Now create a DbContext file inherited from Microsoft.EntityFrameworkCore.DbContext
class.
public class EFContext : Microsoft.EntityFrameworkCore.DbContext { }
To work with SQL server database we need to use UseSqlServer(conString)
method in configuration, so simply override the OnConfiguring
method as example below.
Now you may not find usesqlserver method in .net core 3.1 version, so we need to install an additional package Microsoft.EntityFrameworkCore.SqlServer
using nuget package manager, after installing the package you will be able to use the extention method UseSqlServer("connection-string")
as shown in code below.
Make sure you have added namespace using Microsoft.EntityFrameworkCore;
in you class file.
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { if (!optionsBuilder.IsConfigured) { optionsBuilder.UseSqlServer(conString); } base.OnConfiguring(optionsBuilder); }
You can build an ASP.NET Core MVC application that performs basic data access using Entity Framework Core.
Entity Framework Core is the new form of ORM and improved version of Entity Framework 6 for .NET Core Framework. EF Core supports two database approaches
Here are few important links for Entity Framework Core
Here are some new features of EF Core which were not supported in earlier EF versions
Entity Framework Core uses different provider models for accessing different databases. You can install EF Core providers using NuGet packages