ASP.NET Core Web API .NET 8 2024 - 3. Entity Framework

แชร์
ฝัง
  • เผยแพร่เมื่อ 3 ก.พ. 2025

ความคิดเห็น • 142

  • @TheJunioGG
    @TheJunioGG ปีที่แล้ว +68

    Great course! I don't know if I did something wrong, but a needed to run this command before the migrations int "dotnet tool install --global dotnet-ef --version 8.0.0"

    • @graysongoates7452
      @graysongoates7452 ปีที่แล้ว +4

      Thank you, internet friend. This helped me so much

    • @Suarvae
      @Suarvae 11 หลายเดือนก่อน +1

      An OG indeed

    • @metshehu3858
      @metshehu3858 10 หลายเดือนก่อน +3

      i love you men

    • @jakeaustin2
      @jakeaustin2 7 หลายเดือนก่อน +2

      What a legend. Thanks for saving us all 😂

    • @kaujla8435
      @kaujla8435 3 หลายเดือนก่อน +1

      My brother, you're a saint

  • @lashondamiller2982
    @lashondamiller2982 ปีที่แล้ว +78

    Hey y'all, if you had an issue with the "dotnet ef migrations add init" part
    **run this line in the terminal**
    *dotnet tool install --global dotnet-ef --version 8.0.0*
    I specifically set it for the version he used in the video, but if you want to use a newer or older version, make sure you change that end part. You should be able to do the migrations add init now 😎

    • @TeddySmithDev
      @TeddySmithDev  ปีที่แล้ว +10

      yes, thank you (and the one other person) for posting this. helps people troubleshoot issues.

    • @vutungly2004
      @vutungly2004 10 หลายเดือนก่อน +2

      thank you

    • @АшрафСадыхбеков-й3с
      @АшрафСадыхбеков-й3с 8 หลายเดือนก่อน +2

      thank you! save me huge time!)

    • @nenygaming11
      @nenygaming11 7 หลายเดือนก่อน +1

      thank u🥰

    • @jevi08
      @jevi08 6 หลายเดือนก่อน +1

      thank you so much

  • @ScottMeesey
    @ScottMeesey 9 หลายเดือนก่อน +19

    It is SO encouraging to hear a online tutor like yourself say "PLEASE no errors. PLEASE. Thank you God." :)

  • @joaogabrielv.m328
    @joaogabrielv.m328 ปีที่แล้ว +6

    I'm a simple man: Teddy posts a video, I open youtube app to give a thumbs up and support his channel

  • @rawroba
    @rawroba 4 หลายเดือนก่อน +7

    for anyone that confused on what to pick for server name, once you have already installed sql server, in the pop up window within MSSMS, right beside the Server name:
    - click on the arrow and a drop down will open up
    - then select browse for more
    - then click on database engine
    and now you should be able to see and select the sql server you previously installed.

  • @alreadyghosts7727
    @alreadyghosts7727 4 หลายเดือนก่อน +1

    "A sideways database row." Terrific! You have a gift for teaching, not just coding.

  • @caseyspaulding
    @caseyspaulding 10 หลายเดือนก่อน +3

    Program.cs is the back of the TV. Great analogy. 😄

  • @timomartinson
    @timomartinson 11 หลายเดือนก่อน

    I have to thank you for all the effort you put into these videos. They are great. Keep em up, bro!

  • @SeethMione
    @SeethMione 6 หลายเดือนก่อน +1

    learning with you is exciting and non-boring! thanks a lot.

  • @Suarvae
    @Suarvae 11 หลายเดือนก่อน

    This is pretty great ... Thanks for making this series man

  • @hype_x6083
    @hype_x6083 5 หลายเดือนก่อน +4

    i keep getting this errror when i try running the dotnet ef database update command. "The ConnectionString property has not been initialized"

  • @alanthomasgramont
    @alanthomasgramont 6 หลายเดือนก่อน +1

    base is calling the parent constructor with the matching signature. So calling base(dbContextOptions) will look in the parent class (also called the super class) for a consturctor with the signature DBContext(DbContextOptions options) and call that BEFORE it calls any of your constructor body.

  • @Rezishon
    @Rezishon ปีที่แล้ว +11

    The connection string somehow confused me. There is {PCNAME} part which I changed but I didn't see the \\SQLEXPRESS which also is part of the data source. Please edit it for noob programmers like me who don't read the code completely😂❤

    • @kevinm9682
      @kevinm9682 11 หลายเดือนก่อน

      you should not need the \\SQLEXPRESS

    • @wesleymaia9380
      @wesleymaia9380 10 หลายเดือนก่อน

      Your comment helped me. Thanks.

    • @davincedev
      @davincedev 7 หลายเดือนก่อน

      But what i change to?

    • @davincedev
      @davincedev 7 หลายเดือนก่อน

      Nevermind, for someone stuck there just remove the part \\SQLEXPRESS

    • @emresalaman759
      @emresalaman759 6 หลายเดือนก่อน

      @@davincedev you should delete \\SQLEXPRESS if you couldn't find out

  • @raulpetcu9202
    @raulpetcu9202 10 หลายเดือนก่อน +4

    make sure to to put semicolon ( ; ) at the end of the connection string

  • @Himakevolution
    @Himakevolution 8 หลายเดือนก่อน +1

    I could not run the command "dotnet ef migrations add init" although I run "dotnet tool install ..." before. It's always error: Could not execute because the specified command or file was not found.
    Possible reasons for this include:
    * You misspelled a built-in dotnet command.
    * You intended to execute a .NET program, but dotnet-ef does not exist.
    * You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.

  • @nenygaming11
    @nenygaming11 7 หลายเดือนก่อน +2

    hello brother why my = dotnet ef migrations add init not work pls help me !

  • @ElliotHoward-f4x
    @ElliotHoward-f4x 10 หลายเดือนก่อน +3

    I keep getting an error when trying to do the dotnet ef update command.
    A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SNI_PN11, error: 26 - Error Locating Server/Instance Specified)
    I have tried multiple different strings for the server name, but ultimately I think it should just be Server->properties->Name.
    The database name is definitely correct. The database exists in the server, I can see it. I'm not sure what's wrong :/ . Also tried changing SQLEXPRESS to mssqllocaldb as someone suggested it but that didn't work either.

    • @TeddySmithDev
      @TeddySmithDev  10 หลายเดือนก่อน

      It might be the properties. If you google the error sometimes weird properties like “ssl=true” can cause strange errors. Also might be your password is incorrect. Sometimes wrong password will give instance error.

    • @anyta16
      @anyta16 10 หลายเดือนก่อน +1

      I had the same problem like you and I had to is: in Microsoft SQL Server Management, under your finshark database name(or your DBname), before last option, is SQL Server Agent, right-click on it, start it, and then go back to vs code and try the update command.

    • @ElliotHoward-f4x
      @ElliotHoward-f4x 10 หลายเดือนก่อน

      @@anyta16 Thanks for the help! I'll give this a go tomorrow :)

    • @anyta16
      @anyta16 10 หลายเดือนก่อน

      @@ElliotHoward-f4x and I also change the ConnectionStrings from appsettings.json to "Server={computer name};Database=finshark{or database name};Integrated Security=True;Encrypt=False;TrustServerCertificate=True;" . Hope it will works.

    • @ElliotHoward-f4x
      @ElliotHoward-f4x 10 หลายเดือนก่อน +2

      Strangely I had to remove the SQLEXPRESS and it worked, otherwise it was still giving me an error. Not sure if this is going to cause me future problems as I am unsure what this does.

  • @melittasingarayan9875
    @melittasingarayan9875 หลายเดือนก่อน +1

    Did anyone land in the below error while trying to build using command "dotnet ef migrations add init"
    Unable to create a 'DbContext' of type ''. The exception 'Object reference not set to an instance of an object.' was thrown while attempting to create an instance.

    • @sepi4
      @sepi4 3 วันที่ผ่านมา

      Yes, I had this error. In my case issue was with models Comment.cs and Stock.cs something was written incorrectly. I copy pasted this files from github and all worked after that.

  • @aprodigykid1247
    @aprodigykid1247 ปีที่แล้ว +1

    The question I have is with reading the database data. I do my migrations to my data base smoothly and changed are made when i changed my models. My problem is when trying to execute an entity framework and just getting data from the data already in the DB. It shows that there is no data in the data base when there is.

    • @TeddySmithDev
      @TeddySmithDev  ปีที่แล้ว

      What Linq query are you using?

    • @aprodigykid1247
      @aprodigykid1247 ปีที่แล้ว

      _context.Analyses.OrderBy(p => p.AnalyseId).ToList();
      @@TeddySmithDev

  • @TheExplodingOtter
    @TheExplodingOtter 5 หลายเดือนก่อน +4

    Anyone else get the issue where the comment and stock tables arent created after they run "dotnet ef database update"

    • @mertkayaer8964
      @mertkayaer8964 3 หลายเดือนก่อน +1

      I got the same problem and actually can't solve it. When I try to update other migrations to the database, it gives me errors like it already created the tables. And it functions like it created but I can't see them in the Tables folder. I'm confused

    • @stephanieezat-panah7750
      @stephanieezat-panah7750 หลายเดือนก่อน

      most frustrating! I am seeing such:
      info: Microsoft.EntityFrameworkCore.Migrations[20402]
      Applying migration '20241219014859_init'.
      info: Microsoft.EntityFrameworkCore.Database.Command[20101]
      info: Microsoft.EntityFrameworkCore.Database.Command[20101]
      Executed DbCommand (7ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      info: Microsoft.EntityFrameworkCore.Database.Command[20101]
      Executed DbCommand (7ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
      VALUES (N'20241219014859_init', N'8.0.8');
      so yes, it LOOKS as if they ARE created, but I am seeing nothing in SQL Server....
      .

    • @vasil5077
      @vasil5077 หลายเดือนก่อน +1

      I was having the same issue and nothing was helping but I finally noticed that I put the name of the database in the connection string in braces cause that was how i copied the line from the description. Just check if that is not the issue with you 😊😊

  • @belkhiriasadok7245
    @belkhiriasadok7245 6 หลายเดือนก่อน +2

    Sir ,Please, help me i got this error: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SNI_PN11, error: 26 - Error Locating Server/Instance Specified)

    • @belkhiriasadok7245
      @belkhiriasadok7245 6 หลายเดือนก่อน

      i found the solution all you have to do is removing "\\SQLEXPRESS" from the connection string

    • @AllenWolff
      @AllenWolff 2 หลายเดือนก่อน

      Type services on your windows search bar, then search for "SQL Server (SQLEXPRESS)" & the "SQL Server (SQLEXPRESS)", make sure they are in a running status, if not right click and press start.

  • @sergiocastellani9823
    @sergiocastellani9823 19 วันที่ผ่านมา

    he man just a quick question: to connect to PostGreSQL is it enough to install Npgsql and modify the connection string accordingly? i ask this because i cannot install SQLserver in my company laptop...thanks in advance mate!

  • @mansur.dev1999
    @mansur.dev1999 7 หลายเดือนก่อน

    Wow thank Man for this course

  • @ChandlorMartin
    @ChandlorMartin 3 หลายเดือนก่อน

    Not sure if anybody else had this issue but when I run "dotnet build" I get an error with "The type or namespace name 'User' could not be found (are you missing a using directive or an assembly reference?)".
    I am using a class called User instead of Stock but it is otherwise the same so I'm not sure what's up with that

  • @vvp6552
    @vvp6552 26 วันที่ผ่านมา

    Am i have to create database manually? Can programm code do it for me ?

  • @user-zq1um1mf1s
    @user-zq1um1mf1s 7 หลายเดือนก่อน

    Make sure to turn off your antivirus if you have one for the dotnet ef migrations add init part of the video. Kept getting a The requested operation cannot be performed on a file with a user-mapped section open error.

  • @Zara2379M
    @Zara2379M 3 หลายเดือนก่อน

    Excuse me I can’t find dbcontext in suggestions list what will doing?

  • @brownguyart
    @brownguyart 5 หลายเดือนก่อน +1

    How did he make the database server? I opened sql management studio and Its asking me server name, what should i write in it??

    • @rawroba
      @rawroba 4 หลายเดือนก่อน +1

      right beside the Server name:
      - click on the arrow and a drop down will open up
      - then select browse for more
      - then click on database engine
      and now you should be able to see and select the sql server you previously installed.

  • @mentedecuriosidad
    @mentedecuriosidad หลายเดือนก่อน

    great job!, amazing bro

  • @thecap7249
    @thecap7249 5 หลายเดือนก่อน +1

    Was there any speific reason visual studio was not used here ?

    • @TeddySmithDev
      @TeddySmithDev  5 หลายเดือนก่อน +1

      The biggest complaint of people learning C# is “VS is too hard to learn”
      VS Code is way easier for new people and those coming over for python/js

  • @EhijeneGideon
    @EhijeneGideon 5 หลายเดือนก่อน +1

    No project was found. Change the current working directory or use the --project option. please am getting this error when i tried creating the migrations please anybody can help me

    • @TGrod
      @TGrod หลายเดือนก่อน

      The commentator, probably, does not need this information, but for everyone else, you need to go specifically to the project folder. The default structure can be as follows: //
      You are probably in the first folder , so you need to go to the subfolder:
      cd

  • @memoxcan1
    @memoxcan1 10 หลายเดือนก่อน +1

    Actually, I tried many different queries and did a lot of research before asking this question, but I'm sorry I couldn't come to a conclusion. My question is, is there a solution for macOS for the query we use here in DefaultConnection or a related guide?

    • @TeddySmithDev
      @TeddySmithDev  10 หลายเดือนก่อน +2

      I updated the description to include Azure Edge connection string. If you have ARM chip you will have to run a different version of MSSQL called "Azure Edge" inside a docker container. Also, instead of SSMS, you use Azure Data Studio (which is honestly better in my opinion). If you have Intel chip, you can use regular MSSQL docker image.
      Here is blog post that describes down below.
      community.appsmith.com/tutorial/running-mssql-server-your-mac-m1m2m3-using-docker-bonus-secret-end

    • @mc-ty4br
      @mc-ty4br 3 หลายเดือนก่อน

      Here is what eventually worked for me:
      1. Google: "Quickstart: Run SQL Server Linux container images with Docker" then follow the steps to run the container
      2. Continue the steps 👆 to ssh to the container and create a database
      3. "DefaultConnection": "Server=localhost\\mssql-express,1433;Database=;User ID=sa; Password=;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"

  • @ghaithchikhalchabab5676
    @ghaithchikhalchabab5676 11 หลายเดือนก่อน

    In SQL Server Management Studio, what server name should I write? I have just installed it for the first time and am going step by step in this course. Should I understand how SSMS works before taking this course?

    • @TeddySmithDev
      @TeddySmithDev  11 หลายเดือนก่อน +2

      You should be able to use the connection string in description.
      The only thing you will need to learn in SMSS is:
      1. Find table you want to look at
      2. Right click
      3. Select "Select Top 1000"
      4. Or if you want to edit, "Edit Data"
      Those are only commands I used in entire course.

  • @santkumarvishwakarma5289
    @santkumarvishwakarma5289 7 หลายเดือนก่อน +6

    Gr8!, but I had used this command before ef mingration : "dotnet tool install --global dotnet-ef --version 8.0.6"

  • @ajaysh73
    @ajaysh73 ปีที่แล้ว +1

    I have been using VS Code for React for a long time and would love to use for .Net development as well as you are using here but per your experience does it offer same kind of user experience that Visual Studio 2022 gives for .Net development work? I'll appreciate your feedback.

    • @TeddySmithDev
      @TeddySmithDev  ปีที่แล้ว +1

      Yeah, I actually prefer it these days because it’s lightweight and works better with React/Angular. The only downside is VS code doesn’t have GUI for database, unit testing is meh, and you have to type commands to run.

    • @ajaysh73
      @ajaysh73 ปีที่แล้ว

      @TeddySmithDev thank you for the feedback, Teddy. I would start using VS code for .Net development going forward. I like it being lightweight.

  • @kevinpham661
    @kevinpham661 8 หลายเดือนก่อน

    Hi Teddy, thank you so much for your video. Is there any ways you can create another one to help Mac User? I am getting a lil confused with Azure Data Studio.
    Thanks

  • @Adrian-di2zg
    @Adrian-di2zg ปีที่แล้ว +1

    Why did you say that probably we are not going to work with migrations in a work environment? Of course these are great news for me because it made things easier, but why?

    • @TeddySmithDev
      @TeddySmithDev  ปีที่แล้ว +1

      Because as great as migrations are there are so many small processes in SQL that migrations cannot account for or anticipate. One small mistake and the whole entire migrations will be messed up for developers down the line so people end up just making database changes with raw SQL.

  • @vasirehman8361
    @vasirehman8361 5 หลายเดือนก่อน

    Bro, just wanna give my side of story to you. In the previous video you have terminal disappeared may be for giving clear pictures of the content but in the these video it came back from start of the video i tried to get the terminal but it ended in failure and after allot of time applied i got to terminal still it when for error. So i was struck at these point. My request is your explanation is good but we are beginner we don’t know much of content of studio code we get confused and get struck overall we remaining same and not able to learn. So, kindly explain all the things please.

  • @mischief9499
    @mischief9499 11 หลายเดือนก่อน

    My vscode is not showing suggestions and not auto importing too, i have the c# extension and dev kit extension too, i have c# intellisense extension too

    • @adrianhernandez5555
      @adrianhernandez5555 11 หลายเดือนก่อน

      I had the same issue. What I did to fix this issue was uninstalled and reinstalled all of the extensions that this project uses.

    • @mischief9499
      @mischief9499 11 หลายเดือนก่อน +1

      @@adrianhernandez5555 hi thx for replying. I fixed this issue 2 weeks ago by simply uninstalling the dev kit extension, everything works fine now

  • @hassneltokhy
    @hassneltokhy หลายเดือนก่อน

    Can I use MySQL instead of SQL Server because I'm struggling to run it on Mac M1.

    • @TeddySmithDev
      @TeddySmithDev  หลายเดือนก่อน

      Yeah sure you can easily swap it out with a few lines of code.

  • @howlett3527
    @howlett3527 6 หลายเดือนก่อน

    i did everything u did, and i had "The ConnectionString property has not been initialized." error when im tryin dotnet ef database update. Did i have problem with sql server management?

    • @davitharutyunyan5777
      @davitharutyunyan5777 6 หลายเดือนก่อน +1

      try to go to the properties of appsettings and set the CopyToOutputDirectory to always

  • @vutungly2004
    @vutungly2004 10 หลายเดือนก่อน

    Hi mr.Smith, hi everyone. I've follow this video but I got stuck when I run the command ' dotnet ef migrations add init ', it printed Build succeed AND the error : "The property 'Stock.Industry' could not be mapped because it is of type 'string', which is not a supported primitive type or a valid entity type. Either explicitly map this property, or ignore it using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'." I certainly write the same syntaxs like you. Can you recommend way to solve the problem ? Thank you so much.

    • @TeddySmithDev
      @TeddySmithDev  10 หลายเดือนก่อน

      That's very strange error because string should work. Try deleting migrations folder and renaming the migration to different name. Example: "dotnet ef migrations add FirstInit"

    • @TeddySmithDev
      @TeddySmithDev  10 หลายเดือนก่อน

      could also be that you have private or no set on the Stock -> Industry property

  • @tryinfo
    @tryinfo 10 หลายเดือนก่อน

    How will install dependency for frontend?

  • @antoniofuller2331
    @antoniofuller2331 3 หลายเดือนก่อน

    The company I work at are current doing a migration so show us how to do it 10:03

  • @fercho1463
    @fercho1463 11 หลายเดือนก่อน +1

    I can´t install MicrosoftEntityFrameworkCore.SqlServer 8.0.2 using .net 8.0, why? anybody with the same problem?

    • @TeddySmithDev
      @TeddySmithDev  11 หลายเดือนก่อน

      Does it give error? You may need to install package from pinned comment.

    • @fercho1463
      @fercho1463 11 หลายเดือนก่อน

      the same problem using visual studio comunity 2022@@TeddySmithDev

  • @usmanghause7782
    @usmanghause7782 7 หลายเดือนก่อน

    Well for anyone thinking why we actually have to run this command (dotnet tool install --global dotnet-ef --version 8.*) in the terminal for Migrations to become possible? well the thing is we currently didn't had any Entity Framework Installed for our project so due to lack of the instructions for EF the Terminal just doesn't knows any Commands (dotnet ef migrations add init) to generate Migrations so we RUN this Command dotnet tool install --global dotnet-ef --version 8.* specifying required Version the EF gets installed for our project and Voila now you can finally make migrations possible for creating and managing Databases for your project.

  • @metshehu3858
    @metshehu3858 10 หลายเดือนก่อน

    yo if i have a mac can i run a docer image or can i just use. a mysql database ?

    • @TeddySmithDev
      @TeddySmithDev  10 หลายเดือนก่อน

      For ARM chip, you use “Azure Edge” docker image. For Intel, you use MSSQL docker image. No way to run sql server directly on Mac, but it’s super easy and good to put on your resume as well.

    • @metshehu3858
      @metshehu3858 10 หลายเดือนก่อน

      if you dont mind me asking how do i connect a mysql database insted of this ?
      i tryed some other tutorails but nothing is working@@TeddySmithDev

    • @metshehu3858
      @metshehu3858 10 หลายเดือนก่อน

      @@TeddySmithDev yo got to ask how can i use the mysql database instes of mssql cuz ime trying to but its giving me a lot of problems

  • @MrTadsuki
    @MrTadsuki 10 หลายเดือนก่อน

    Can we use Azure Data Studios instead of SSMS or would you recommend we just download SSMS to follow along
    EDIT: I'm on MAC and it looks like Azure Data Studios is the only option.

    • @TeddySmithDev
      @TeddySmithDev  10 หลายเดือนก่อน

      Yeah from here on out I’m actually going to start using Azure Data Studios for future courses.

    • @metshehu3858
      @metshehu3858 10 หลายเดือนก่อน

      i love you men

  • @PhuongHoHoang-wn5ju
    @PhuongHoHoang-wn5ju 6 หลายเดือนก่อน

    could you please give me the vs code extensions or settings, sir ? I want my vs code themes look like yours

  • @Khal_Rheg0
    @Khal_Rheg0 8 หลายเดือนก่อน

    Thank you!

  • @ajmaln73
    @ajmaln73 2 หลายเดือนก่อน

    give me your vscode settings.json
    theme you use etc

  • @AlgoXperience
    @AlgoXperience 8 หลายเดือนก่อน

    2nd and 3rd video are same same i guesss please check and update

  • @sandrotabatadze3768
    @sandrotabatadze3768 5 หลายเดือนก่อน

    i had an little issue: i was in incorrect directory so pay attention when adding migrations

  • @Gokuuhanten
    @Gokuuhanten 4 หลายเดือนก่อน

    thank you

  • @manishsci-figaming
    @manishsci-figaming 4 หลายเดือนก่อน

    what the fuck is the course about .net i dont understand

  • @alicankurus
    @alicankurus 6 วันที่ผ่านมา

    random comment

  • @АнтонБалашов-м4д
    @АнтонБалашов-м4д 10 หลายเดือนก่อน +3

    error: 26 - Error Locating Server/Instance Specified
    Try to cut \\SQLEXPRESS from the DefaultConnection in appsettings.json

    • @shopedevs
      @shopedevs 10 หลายเดือนก่อน

      Hey, thanks for this.

    • @MrHITStyle
      @MrHITStyle 9 หลายเดือนก่อน

      It worked! Thanks a lot!