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

Комментарии • 73

  • @nhloniphoxaba6763
    @nhloniphoxaba6763 Год назад +21

    There's not Startup Class in .NET 6, what I should do

    • @bogdantodoran1135
      @bogdantodoran1135 11 месяцев назад

      Same

    • @bobannoveski3914
      @bobannoveski3914 11 месяцев назад +9

      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

  • @2005Azm
    @2005Azm 3 года назад +6

    Another outstanding tutorial !Your teaching style is awesome.. makes it easy for anybody to understand...

  • @shivajisuryavanshi8431
    @shivajisuryavanshi8431 Год назад +6

    what if we don't have startup.cs do we have to create the startup.cs file or anthing else

    • @DotNetHow
      @DotNetHow  Год назад +11

      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

    • @phixvsm1999
      @phixvsm1999 Год назад +2

      @@DotNetHow Thanks 😄 I was looking for this answer

    • @DhirajMishra-pd8hj
      @DhirajMishra-pd8hj Год назад +2

      @@DotNetHow thanks am also looking for this answer

    • @rajeshtammineni3584
      @rajeshtammineni3584 Год назад

      @@phixvsm1999 how did you type the code in program.cs file..?

  • @handanunal4040
    @handanunal4040 2 года назад +1

    Thanks, videos are very comprehensive, clear.

  • @mrunmayeebangar2586
    @mrunmayeebangar2586 Год назад +2

    There is no startup class in . Net 7...
    What should I do?

  • @fawaz-barca6734
    @fawaz-barca6734 2 года назад +1

    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'.

  • @satyajitdandi7888
    @satyajitdandi7888 Год назад +1

    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.

  • @swift849
    @swift849 2 года назад +5

    my project no has Startup.cs files

  • @osamaasender2448
    @osamaasender2448 10 месяцев назад

    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

  • @HananeRaib
    @HananeRaib Год назад +1

    I can't see the startup.cs file in my project ?? what should I do in this case

    • @DotNetHow
      @DotNetHow  Год назад

      You can use the Program.cs instead

  • @abal6127
    @abal6127 Год назад

    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?

  • @jeremygann9247
    @jeremygann9247 Год назад +1

    ugh... mine does not have a startup.cs... where do I add the dbContext in this case?

    • @DotNetHow
      @DotNetHow  Год назад +1

      You can add it directly into Program.cs

  • @srikanna6938
    @srikanna6938 11 месяцев назад

    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.

  • @shravandevadiga2399
    @shravandevadiga2399 Год назад

    but where in program.cs ,,,, like above which line or code as you said AddControllerWithView();

  • @Choigo3
    @Choigo3 2 года назад +1

    Is it possible to use DbContext on the Client side Web App? without API Server that means Directly contacting SQL server.

    • @DotNetHow
      @DotNetHow  2 года назад +1

      No, it is not. You need to configure it on the back-end.

  • @pemz5517
    @pemz5517 5 месяцев назад

    Hello Good Day!. In the ep12 where can i put the code the services.Adddbcontext(); file? into the program cs?

    • @DotNetHow
      @DotNetHow  5 месяцев назад +1

      After builder. So, builder.Services…

    • @pemz5517
      @pemz5517 5 месяцев назад

      @@DotNetHow thanks sir.

    • @DotNetHow
      @DotNetHow  5 месяцев назад

      @@pemz5517 you are welcome. I am glad it worked

  • @shivajisuryavanshi8431
    @shivajisuryavanshi8431 Год назад

    thank you so much

  • @arkadiusega4857
    @arkadiusega4857 Год назад

    Where is link download the Database?

  • @claudiotorres9138
    @claudiotorres9138 Год назад

    which version of .NET are you using?

    • @DotNetHow
      @DotNetHow  Год назад

      5, but you can use other versions as well

  • @preetmaheshwary9597
    @preetmaheshwary9597 2 месяца назад

    CS0311 'DbContextOptions'. eTickets There is no implicit reference conversion from eTickets.Data.AppDbContext' to 'Microsoft.EntityFrameworkCore. DbContext'

  • @issamelhoss3067
    @issamelhoss3067 2 года назад

    how do i do this in dotnet6 in the program.cs file? please help

  • @ФазлиддинЮлдашев-и7р

    can you make more video with russian subtitles?)

  • @efficascenSnorter
    @efficascenSnorter Год назад

    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.

    • @DotNetHow
      @DotNetHow  Год назад +1

      What errors fo you get and how are you installing it?

    • @DevWebi
      @DevWebi Год назад +1

      install a old version of EF, not the last one

    • @efficascenSnorter
      @efficascenSnorter Год назад +1

      @@DotNetHow Continuing this project again lol I already fixed it by installing the framework to version 5.0

    • @DotNetHow
      @DotNetHow  Год назад

      @@efficascenSnorter glad you fixed it. but, you can also add some additional code in Program.cs to fix it for other versions as well.

  • @caominh1412
    @caominh1412 Год назад

    Sorry, I am beginner and I want to build lines 2,3,4,5 like the video. Thanks

  • @RoshelJudith
    @RoshelJudith Год назад

    is this done using sql server databse?

  • @darshanpacharne2614
    @darshanpacharne2614 Год назад

    I cant find any startup file in my solution explorer.. please advice

    • @DotNetHow
      @DotNetHow  Год назад

      You can add it as custom file, or you can type your code in the Program.cs file

    • @noura715
      @noura715 Год назад +1

      @@DotNetHow it will be
      builder.Services.AddDbContext();
      right?

    • @DotNetHow
      @DotNetHow  Год назад

      @@noura715 correct

    • @muhamedabdella7779
      @muhamedabdella7779 Год назад

      @@noura715 how can i do this plz ?

    • @waqarnazeer7740
      @waqarnazeer7740 Год назад +1

      @@DotNetHow can someone please where exactly to add this code

  • @ahimachaliboy162
    @ahimachaliboy162 2 года назад

    Sir there is no Startup.cs in my Visual studio code

    • @DotNetHow
      @DotNetHow  2 года назад +1

      Are you using .NET 6?

    • @_AjayGhenand
      @_AjayGhenand Год назад

      @@DotNetHow yes

    • @tacca4720
      @tacca4720 Год назад

      @@_AjayGhenand In Program.CS, add builder.Services.AddDbContext();