12. Adding your DbContext file | ASP.NET MVC
HTML-код
- Опубликовано: 16 сен 2024
- 📌 Course link: bit.ly/3CWvkqk
📌 Source code: bit.ly/3jvocZK
------------------------------------------------------------------
The DbContext file is also known as the translator file between the Models (C# classes) and the data storage (SQL in our case).
You can create your custom DbContext by inheriting from the DbContext base class and configure your class to be used to translate C# code into SQL and vice versa.
===================================
You can also watch my courses on:
🎯 Udemy: bit.ly/2MaEA5r...
🎯 LinkedIn Learning: bit.ly/2NJ5PEF...
🎯 Pluralsight: bit.ly/2EsgjlJ...
===================================
#mvc #aspnetcore #csharp
There's not Startup Class in .NET 6, what I should do
Same
builder.Services.AddDbContext(options => options.UseSqlServer(
builder.Configuration.GetConnectionString("DefaultConnectionString")
));
Add this in program.cs file, and watch the next video for sql configuration.@@bogdantodoran1135
Another outstanding tutorial !Your teaching style is awesome.. makes it easy for anybody to understand...
what if we don't have startup.cs do we have to create the startup.cs file or anthing else
No, you do not have to. In .NET 6+ that file is not part of the solutionm anymore. You can type the code in the Program.cs file
@@DotNetHow Thanks 😄 I was looking for this answer
@@DotNetHow thanks am also looking for this answer
@@phixvsm1999 how did you type the code in program.cs file..?
Thanks, videos are very comprehensive, clear.
There is no startup class in . Net 7...
What should I do?
ya same buddy !!! did you got any solutions ????/
pls what i do with this error
=====>System.InvalidOperationException: Unable to determine the relationship represented by navigation 'Cinema.Movies' of type 'List'. Either manually configure the relationship, or ignore this property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.
As you instructed in my project there is no such file created as startup.cs to configure dbcontext!! what should i do ?? Instead I have program.cs file.
Yes, that is the file that you need to use.
@@DotNetHow okay thank you
my project no has Startup.cs files
Because you need to create the project in DotNet core 5, NOT 6
@@osamahashim how to get startup.cs file plz help
in Program.CS , add builder.Services.AddDbContext();
@@tacca4720 Thanks Tacca
Very Helpful
@@tacca4720 Thanks
I don't think you need to do this anymore... please correct me if am wrong
you can just add Dbset in the already automated AppDbContext file.. .
that is the case when you choose (MVC) when configuring your new project
I can't see the startup.cs file in my project ?? what should I do in this case
You can use the Program.cs instead
nice job.
I have concern. I can see a lot of RUclips Tutorial use Entity framework( DbContext) when they want to deal with a DB.
I'm a guy who uses SQl client and store procedures to deal with the DB (Since I'm good with a DB).
I don't know why but I have this believe using this method, gives me more control.
IS it a bad practice and why?
ugh... mine does not have a startup.cs... where do I add the dbContext in this case?
You can add it directly into Program.cs
Hi , I am getting error while installing Microsoft entity framework. Could you please help me on it. error : Installing 'Microsoft.EntityFrameworkCore' failed Additional info: Package restore failed. Rolling back package changes.
but where in program.cs ,,,, like above which line or code as you said AddControllerWithView();
Is it possible to use DbContext on the Client side Web App? without API Server that means Directly contacting SQL server.
No, it is not. You need to configure it on the back-end.
Hello Good Day!. In the ep12 where can i put the code the services.Adddbcontext(); file? into the program cs?
After builder. So, builder.Services…
@@DotNetHow thanks sir.
@@pemz5517 you are welcome. I am glad it worked
thank you so much
You are welcome
Where is link download the Database?
which version of .NET are you using?
5, but you can use other versions as well
CS0311 'DbContextOptions'. eTickets There is no implicit reference conversion from eTickets.Data.AppDbContext' to 'Microsoft.EntityFrameworkCore. DbContext'
how do i do this in dotnet6 in the program.cs file? please help
same question ?
can you make more video with russian subtitles?)
Hello I have a problem in installing the Microsoft Entity framework core, I really want to continue this project I hope you can help me with this, thanks.
What errors fo you get and how are you installing it?
install a old version of EF, not the last one
@@DotNetHow Continuing this project again lol I already fixed it by installing the framework to version 5.0
@@efficascenSnorter glad you fixed it. but, you can also add some additional code in Program.cs to fix it for other versions as well.
Sorry, I am beginner and I want to build lines 2,3,4,5 like the video. Thanks
How can I help you?
is this done using sql server databse?
Yes
I cant find any startup file in my solution explorer.. please advice
You can add it as custom file, or you can type your code in the Program.cs file
@@DotNetHow it will be
builder.Services.AddDbContext();
right?
@@noura715 correct
@@noura715 how can i do this plz ?
@@DotNetHow can someone please where exactly to add this code
Sir there is no Startup.cs in my Visual studio code
Are you using .NET 6?
@@DotNetHow yes
@@_AjayGhenand In Program.CS, add builder.Services.AddDbContext();