In this video we will discuss the significance of the DbContext class in Entity Framework Core
Text version of the video
https://csharp-video-tutorials.blogsp...
Slides
https://csharp-video-tutorials.blogsp...
ASP.NET Core Text Articles & Slides
https://csharp-video-tutorials.blogsp...
ASP.NET Core Tutorial
https://www.youtube.com/playlist?list...
Angular, JavaScript, jQuery, Dot Net & SQL Playlists
https://www.youtube.com/user/kudvenka...
One of the very important classes in Entity Framework Core is the DbContext class. This is the class that we use in our application code to interact with the underlying database. It is this class that manages the database connection and is used to retrieve and save data in the database.
To use the DbContext class in our application
We create a class that derives from the DbContext class.
DbContext class is in Microsoft.EntityFrameworkCore namespace.
public class AppDbContext : DbContext
{ }
For the DbContext class to be able to do any useful work, it needs an instance of the DbContextOptions class.
The DbContextOptions instance carries configuration information such as the connection string, database provider to use etc.
To pass the DbContextOptions instance we use the constructor as shown in the example below.
We will discuss more about the DbContextOptions class in our next video when we discuss database connection string in ASP.NET Core.
public class AppDbContext : DbContext
{ public AppDbContext(DbContextOptions[AppDbContext] options) : base(options) { }
}
The DbContext class includes a DbSet[TEntity] property for each entity in the model.
At the moment in our application we have, only one entity class - Employee.
So in our AppDbContext class we only have one DbSet[Employee] property.
We will use this DbSet property Employees to query and save instances of the Employee class.
The LINQ queries against the DbSet[TEntity] will be translated into queries against the underlying database.
We will see this in action in our upcoming videos.
public class AppDbContext : DbContext
{ public AppDbContext(DbContextOptions[AppDbContext] options) : base(options) { } public DbSet[Employee] Employees { get; set; }
}
To be able to connect to a database we need the database connection string. In our next video, we will discuss, where do define the connection string and using it in Entity Framework Core.
asp.net core docker DbContext in entity framework core | |
| 299 Likes | 299 Dislikes |
| 27,859 views views | 524K followers |
| Science & Technology | Upload TimePublished on 23 Apr 2019 |
Related keywords
ajax meaning,sql server management studio,central park 5,asp.net core github,craigslist nj,asp.net core 3,server status,ajax fc,ajax players,server jobs nyc,asp.net core swagger,sql formatter,credit karma,asp.net machine account,server error in '/' application,servers for minecraft,asp.net core dependency injection,asp.net core 3.0,sql injection,calculator,sql insert,ajax ontario,sqlyog,asp.net mvc tutorial,asp.net core 3 release date,sql server,server job description,asp.net cos'è,sql join,asp.net core web api,ajax jquery,craigslist ny,ajax call,asp.net core 2. guida completa per lo sviluppatore,asp.net core,server pro,server status ffxiv,asp.net zero,cheap flights,server memes,asp.net core hosting,sql date format,chase,serverless architecture,server resume,server books,college football,ajax deadpool,server jobs,cvs,cnn,costco hours,asp.net web api,server side rendering,serverless,sql server 2017,asp.net core download,cool math games,citibank,asp.net core identity,sql union,ajax parking,sql database,asp.net core logging,cunyfirst,ajax post,asp.net guida,ajax jersey,asp.net core razor pages,server duties,asp.net core environment variables,http://asp.net,server 2019,chernobyl,century 21,serverminer,ajax cleaner,asp.net core configuration,ajax marvel,sql like,sql update,asp.net tutorial,asp.net mvc,asp.net core tutorial,sqlite,ajax roster,asp.net core mvc,ajax soccer,chase online,server hosting,costco,server jobs near me,sql meaning,ajax dish soap,sql tutorial,capital one,server rack,sql commands,craigslist,ajax tavern,ajax javascript,ajax request,asp.net core 2.2,sql developer,sql group by,asp.net core signalr,ajax paving,ajax greek,asp.net identity,asp.net core middleware,asp.net download,sql between,
Không có nhận xét nào:
Đăng nhận xét