Entity Framework core 7.0 ( DB First Approach & Code First Approach) | .NET 7 Updates

preview_player
Показать описание
#efcore #dotnetcore #nihiratechiees

This video explains Entity Framework core 7.0 in .NET Core with DB First & Code Approaches.

The Entity Framework provides three approaches to create an entity model

1, Database First
2, Code First
3, Model First

Required packages
================
* Microsoft.EntityFrameworkCore
* Microsoft.EntityFrameworkCore.Design
* Microsoft.EntityFrameworkCore.SqlServer
* Microsoft.EntityFrameworkCore.Tools

Structure of scaffold command is shown below

Scaffold-DbContext [-Connection] [-Provider] [-OutputDir] [-Context] [-Schemas] [-Tables]
[-DataAnnotations] [-Force] [-Project] [-StartupProject] [CommonParameters]

1, Connection – used to provide connection string

2, Provider – used to provide the Provider info

3, OutputDir – Generate model in specific folder

4, Context - provide name of our database context

5, contextDir - Generate dbcontext in specific folder

6, tables – generate models for specific tables

7, DataAnnotations – Generate models with data annotations

8, Force – forcedly updating the existing files

Sample Scaffold command
=======================
Scaffold-DbContext –connection name=constring Microsoft.EntityFrameworkCore.SqlServer -OutputDir Repos/Models –context dbfirstcontext –contextDir Repos –DataAnnotations -f

GitHub Source code link
====================

Join this channel to get access to perks:
Рекомендации по теме
Комментарии
Автор

I came here to stay updated on the latest tips and tricks. Code first is so much more work for an architect. Database first is hands down the way to go in my opinion

RShelper
Автор

I am Database first person, Great stuff.... no time for code first

tokzhee
Автор

very very useful one video and most wanted one thank you so much for touch the backend concepts pls do more backend related video it will help more when connect frontend with backend bro

gladisxavier
Автор

I cant use scaffold command in mac. It shows error. It says that I have to create all database tables first. Could you please suggest me something?

dhwanilgandhi
Автор

Can we copy database tables from one database to another DB using EF code first approach ?

sunnybollepally
Автор

Thanks for the video. Just one thing I would like to point out. Mostly youtube videos about EF Core avoid putting the connection string with authenticacion by user and password. Once I tried it putting "User ID=user; Password=12345678" inside the connection string but it didn't work. I had to put Encrypt=false" too. Is it rigth? or I was doing the wrong way.

sanD-xqnb
Автор

Fantastic tutorial my friend!

May I ask what to do if I do not have an empty Database in SQL server management studio? Create a new one from code in Visual Studio>? Thanks

riddickful
Автор

sir can you tell me how to create multi databases connection string (Dynamic Sql Connection string) using Entity framework For Multi-Tenancy Approach

fahalsalam
Автор

Your scaffolding command doesn't work. I get "Scaffold-DbContext : A positional parameter cannot be found that accepts argument '-'.
At line:1 char:2"

For anyone else struggling, here is how I connected to an instance of AdventureWorks2019 from within a VS 2022 web api;

1) right click on the Database in SQL Server Object Explorer and copy the connection string from the properties.
2) paste this into the appsettings.json (this assumes your connection name is "connection")
3) run this command in the Package Manager Console: Scaffold-DbContext -OutputDir Models

DecentralEyes