ASP.NET Core Web API .NET 6 2022 - 4. Installing Entity Framework

Поделиться
HTML-код
  • Опубликовано: 13 июл 2024
  • ASP.NET Core Web API .NET 6 2022 - 4. Installing Entity Framework
    Github Repo For This Project: github.com/teddysmithdev/poke...
    Twitter: / teddysmithdev
    Github: github.com/teddysmithdev
    Linkedin: / teddy-smith-015ba61a3
  • ХоббиХобби

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

  • @Kyrathos
    @Kyrathos 9 месяцев назад +65

    Man, i hate it when people say "just copy paste it" without at least explaining it a little bit. Lets stick to the most important error for this: the seed from the github repo is the FINISHED seed of the project (i assume), which is incompatable with the current status of the project (e.g. reviews suddenly have ratings, owners have first and last names etc). If some1 has trouble with it, either remove incompatabilities from the seed code or add those to the models.

    • @zulfikarditya7142
      @zulfikarditya7142 6 месяцев назад +1

      agreed

    • @nareshkumarmm6244
      @nareshkumarmm6244 5 месяцев назад +3

      I agree with that, little bit disappointed as I came for an explanation

    • @alimalikashraf7623
      @alimalikashraf7623 5 месяцев назад +3

      yh really poor tutorial tbh. Hes just writing the code and hardly explaining it.

    • @andriitest8015
      @andriitest8015 3 месяца назад

      thanks

    • @damirparipovic5179
      @damirparipovic5179 Месяц назад

      Thank you for this comment. I thought I was going crazy. Updated the models and redid the migration steps. Got it to work :)

  • @mbulelo-damba
    @mbulelo-damba 2 года назад +82

    When I ran the Add-Migration InitialCreate command I got an error. I installed the Microsoft.EntityFrameworkCore and the Microsoft.EntityFrameworkCore.Tools nuggets and everything work. You forgot to install those two. All in all the nuggets I have are :
    Microsoft.EntityFrameworkCore
    Microsoft.EntityFrameworkCore.Design
    Microsoft.EntityFrameworkCore.SqlServer
    Microsoft.EntityFrameworkCore.Tools
    Swashbuckle.AspNetCore

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

    1:03 Create DB
    2:00 Get a connection string
    24:11 Finally someone showed me how to find terminal in Visual Studio :)

  • @raggardy
    @raggardy Год назад +31

    Lol.......I remember watching this a year ago and thinking "WTF, how am I ever gonna learn this?". Now, I've just popped back to recap on fluent api many to manys. You're a star, Teddy and to anyone else thinking "How the f**k am I gonna learn this?", you WILL understand it. Just keep practicing under the guidance of Don Ted ;)

    • @ernest1428
      @ernest1428 Год назад +4

      Beginner here, and I am completely lost, lets see how it goes in one year from now haha

    • @nikolar5847
      @nikolar5847 6 месяцев назад

      So, how's going?@@ernest1428

    • @ronjohnson123
      @ronjohnson123 6 месяцев назад +1

      @@ernest1428 its been 6 months, hows it going?

    • @ernest1428
      @ernest1428 6 месяцев назад

      @@ronjohnson123 I have stopped my studies due to personal reasons, but I finished some courses and reached some SQL queries with .NET, yet I'm planning on continuing next year the journey

    • @raiminjshh
      @raiminjshh 4 месяца назад +1

      @@ronjohnson123 dude gave up

  • @stacktuber
    @stacktuber Год назад +24

    Your tutorials are really enterprise level, most other content creators don't do this on this level, they'll just give it from a locally perspective, I bet you get into design patterns too 🔥

  • @trashbin2166
    @trashbin2166 11 месяцев назад +2

    Teddy, thank you man! You have no idea how helpful I'm finding your content to be!

  • @jorgitorial
    @jorgitorial Год назад +3

    Man! Binge watching (and coding along!) your content. Simply amazing!!!

  • @tebogolem5456
    @tebogolem5456 2 года назад +6

    This was super helpful. I was searching for over 2 days and here's everything I wanted

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

    OMG Your tips to the databases (connection string) was so amazing. Love you good works, thank you!

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

    Dude.. the SQL Server Object Explorer, total diamond right there. Love the tip!

  • @nettech4939
    @nettech4939 9 месяцев назад +2

    This is the best explanation of EF core that I have ever seen. Thank you!

  • @aisyahh38
    @aisyahh38 Год назад +3

    Hello Teddy, I really appreciate your effort making these tutorial videos. Your steps really clear and easy to understand. Thank you very much!

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

    this is the best tutorial I've found so far. As another said this is enterprise level and cover a lot of topics. Nice

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

    love your videos! they are very good for begginers ! Thank you so much for this ! 🥰😍

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

    Awsome! thx for this! You are great!

  • @Console.WriteLine
    @Console.WriteLine Год назад +1

    I've spent weeks trying to watch how to connect to database... and everywhere i was getting some kind of error. but with you it was so easy!

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

    Thank you for such a cool tutorial. Keep it up🤓👍

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

    Thank you sir. This is gold!

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

    Really really useful! Thanks !

  • @Mooseontheloose89
    @Mooseontheloose89 8 месяцев назад +3

    Decided to load my data directly into the database before starting the application build, SQL is easy and it's so much easier to do this at database level rather than scripting something into the application. But good to see that you've used a different way which will help people who lack SQL skills!

  • @daniab2013
    @daniab2013 7 месяцев назад

    You are perfect! Thank you so much!

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

    Hey man you are the best eish thanks Teddy

  • @thekha8490
    @thekha8490 4 месяца назад

    so detail. good luck to you !

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

    I had my troubles with the Rating in the Seed file, but I managed to put it in the PokemonReview model class. Nice little test you put in there

  • @franciscoseverino1851
    @franciscoseverino1851 2 года назад +3

    it works, I had some issues when running the Add-migration InitialCreate command -- after googling I found that I had the connection string spell wrong, but I made it . I proud of myself.
    Thanks for watching hahaha- like teddy said

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

    Excellent!new subscriber here

  • @daukaevk
    @daukaevk 3 месяца назад +1

    Thank you so much for connection string trick

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

    Thanks Prof

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

    nice way to get a connection string!
    But there is simpler way. We can simply connect to server and choose database with connection string from C# level.
    Anyway Loved your content,
    Have a nice day good man

  • @sdscode
    @sdscode 9 месяцев назад

    In this specific scenario, what would be the best way to add additional restrictions to fields? for instance, Max Limit of character of the Country, or the Review integer can only be from 1 to 5?

  • @racmanov
    @racmanov 6 месяцев назад +1

    Pokemon is already plural. SInce (from my long term memory) it actualy stands for Pocket monsters

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

    Amazing!

  • @dataStream2
    @dataStream2 Год назад +3

    Guys if you have a problem with your Add-Migration and nothing helps, make sure you delete the stuff in your Controllers folder in solution explorer. I forgot to delete the WeatherForecast default app controller and it messed up my build

  • @rotface6969
    @rotface6969 11 дней назад

    For those of you watching who might have trouble hooking up your local server or logging into your local server you have to set "Trust Server Certificate" to "True" when prompted.

  • @fercho1463
    @fercho1463 23 дня назад

    Un exito mi amigo Teddy, por favor trata de hacer una aplicacion conjunta de Angular y webApi .netCore, una bien avanzada, como tu sabes! gracias amigo por todo el trabajo que nos brindas. Saludos desde Argentina!

  • @hanchen8106
    @hanchen8106 9 месяцев назад +3

    For anyone unable to add the SQL server in Visual Studio with an error that says cannot connect or find the SQL server, your connection name may not be the same as the Name in the property window. Instead, click on the "View Connection Properties" in the Server Properties window, and copy the server name instead. Put that in the "Server name" in the connect window in VS

    • @saahilsankarb4930
      @saahilsankarb4930 8 месяцев назад

      Thank you, this was so helpful for me. I was facing the same issue and searching for the solution in stackoverflow and all but I couldn't find it. Finally I just went down to the comments and lo and behold! The answer was right there!

  • @MikeKm-hd1ve
    @MikeKm-hd1ve 2 месяца назад

    Hey, is there a way to manually execute the sql queries instead of using the dbcontext models?

  • @mouhssinsouici9290
    @mouhssinsouici9290 7 месяцев назад

    Thank you.. i like this tutorial, actually i'm using as a project for school. just wanna add that there is an easier (for me) way to get the connection string, need just to execute this script >>
    select
    'data source=' + @@servername +
    ';initial catalog=' + db_name() +
    case type_desc
    when 'WINDOWS_LOGIN'
    then ';trusted_connection=true'
    else
    ';user id=' + suser_name() + ';password='
    end
    as ConnectionString
    from sys.server_principals
    where name = suser_name()

  • @almoniaruela.8241
    @almoniaruela.8241 Год назад

    Hello, what is the alternative way if I dont use the Add-Migration? In our task, they say that we need to avoid code first approach with migration.

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

    Great Video so far but why is the screen blurred

  • @elchinmirzayev7631
    @elchinmirzayev7631 Месяц назад

    thank you for like perfect example, because I search what type project can i write, but in the the create seed, I don't understand why you need it? without it isn't good? we can't write different without seed?

  • @hafidazer1634
    @hafidazer1634 6 месяцев назад +1

    Damn thank you Teddy nice video, but I did use the azure sql database and worked perfectly 🤣

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

    I use microsoft sql server at my company, I will back up that claim. Good to know it.

  • @Limitlesss06
    @Limitlesss06 7 месяцев назад

    hey teddy i have been getting nullrefernceexception everywhere like in models where we set the firstname lastname etc

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

    Are you using SQL Express Core?

  • @spencersedano
    @spencersedano 5 месяцев назад +2

    If you get an error after doing everything correct, in .csproj file of your project, change the InvariantGlobalization to false

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

      Thank you. It was bugging me

  • @aymansanusi3510
    @aymansanusi3510 7 дней назад

    Bro how did you get that connection string from the search bar?

  • @user-wf8sx3bo8m
    @user-wf8sx3bo8m 11 месяцев назад

    Lets rock with a database

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

    if there is database already..do we need to use migration...pls rply sir

  • @SS-uf4uq
    @SS-uf4uq Год назад

    i have a proplem, after doing all the steps well, and after updating the database i fount it generate automatically a column with name OwnerId1 in PokemonOwners table, and a column with name CategoryId1 in PokemonCategory table, and i notice that while adding migration the program tell me that it create those 3 columns in the shadow, i don't know the reason, please could you help me with that!

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

    Question, is there a way to avoid all this DB creation by sharing a database? it is not easier to share a file of a database?

  • @theroostingroaster1584
    @theroostingroaster1584 11 месяцев назад +3

    When I copied the seed file from your github I was getting red squiglies under rating for reviews and FirstName and LastName, I don't remember you adding them to the models. Or does this have something to do with the relationships. Maybe I messed up there. IF someone had a similar issue would appreciate any help.

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

      same here, owner does not have first and last name

  • @mitulgupta6164
    @mitulgupta6164 Год назад +4

    If facing an error during Add-Migration InitialCreate with build failed then do some changes owner(first name and last name instead of just name ) and review (add ratings)class

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

      I get this error -> The property or navigation 'Category' cannot be added to the entity type 'PokemonCategory' because a property or navigation with the same name already exists on entity type 'PokemonCategory'.

    • @gio-iova
      @gio-iova 3 месяца назад +2

      thanks a lot,i have not noticed changes in review :)

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

    Any advice to connect visual studio to sql server running in docker. The sql server object explorer doesn't work and google replies suck

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

    I have right columns in database, however there is no data. In the table Countries I have only empty columns Id and Name. How can I fix this?

  • @darkoplax7688
    @darkoplax7688 7 месяцев назад

    can i do this without downloading microsoft SQL ? like doesnt VS have its built in SQL and I have MySQL on my pc as well ?

  • @Abishkar-q1p
    @Abishkar-q1p 9 месяцев назад

    Hello Teddy, In the DataContext example you have done, there seem to be a composite primary key used and when I was using a singular key i got lost can you provide some guidance

    • @TeddySmithDev
      @TeddySmithDev  9 месяцев назад

      You might need to make sure that you are specifying id as primary key? Never seen that issue before so not sure

  • @waynehamberg9248
    @waynehamberg9248 Месяц назад +1

    Tried running this in .Net 8 but built it using .Net 6. All those warnings you got don't work when you get to a an error in Program line where it's trying to run data. Null exception because all those warnings you have in your classes.

  • @maaz6912
    @maaz6912 9 месяцев назад

    Hello teddy. I am getting the tables but there's no data inside. Every command got executed without any errors. Can you give me a clue as to what might have happened?

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

    For me the ServerName was not same as the Name in the Server Properties, It was in View connection properties where its clearly mentioned ServerName might help someone

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

    👍👍

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

    Teddy i followed ur video and everthing work perfectly but i forgot to add 1model to add 1 more model to the database do i need just update databas? Or add migration again?

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

      Both. Run migration and update database in that order.

  • @user-qz5vy1tj5r
    @user-qz5vy1tj5r Год назад

    If you use an local server like he does you can only type "." (a dot without the strings) insteat of copying the whole name

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

    When i run "Update-Database", only the table names (without the data) is being stored at default database named "main". Does it because i didnt follow your database name which i opted to name it as pokemonDB?

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

      No, you can name your database whatever you like. Chances are you missed the step at 3:34 where you type the server name at the top and then *choose from the Database Name field at the bottom.* From the SQL Server Object Explorer you can probably delete your "main" database and then restart from 2:45

    • @nebilimbe
      @nebilimbe 8 месяцев назад

      did you add Services.AddTransient(); in program.cs file? i forgot, I encountered the same error.Then I ran the dotnet run seeddata command.

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

    Are the SQL server and SSMS required? Any tips for mac users?

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

      You can use Azure Data Studio with a docker instance. It works almost exactly the same.

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

    18:57 how come you have "Migrtations" folder out of nowhere?

  • @sdscode
    @sdscode 9 месяцев назад

    To seed data from the command line: `dotnet run seeddata`

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

    Is seed class same as migration..

  • @SweepAndZone
    @SweepAndZone 3 месяца назад

    So I got everything going good, the only issue I have is that the data is not showing up in the actual local SQL database? I tried to run another Database-Update and it even said No migrations were applied. The database is already up to date. But then I check my database and there isnt anything there?

    • @TeddySmithDev
      @TeddySmithDev  3 месяца назад

      Make sure you are not checking the “master” db when checking database.

  • @redlamaravind104
    @redlamaravind104 15 дней назад

    Although tabels are created when migrating, How the data is injected to database??,
    do we previously added in db??
    can anyone explain me pls

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

    How do you set data context when your model differs from tables you want to use ? How to you use tables with different name than model, and different column names?

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

      You can use annotation to change column names. There is also a builder pattern in DbContext that will allow you to make complex adjustments.

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

      @@TeddySmithDev Hey Teddy, that was faster than a cup of coffee. Surely will explore this.

  • @user-jk5gb6bv7p
    @user-jk5gb6bv7p 2 месяца назад

    i cant find the second Pokemonrevapp foulder it just has the initial one

  • @call_me_cat1709
    @call_me_cat1709 9 месяцев назад +2

    I dont know if the course has been updated, but the seed columns doesn't match with de models. Informations such as Rating, FirstName, Last name in Owner and Review does not exist.
    I checked the UML twice and still, seeds does not match.

    • @Ali-vj8hs
      @Ali-vj8hs 5 месяцев назад

      facing same problem

    • @Yagoonerz
      @Yagoonerz 4 месяца назад +1

      He updated it. If you check his Github models file you can see the corrected models. only need to change review and owner models slightly

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

    Teddy I have gone through this entire video series and now I am applying that to another project but I stuck In seed file creation. which you have missed although I have tried several ways to create it and created also and when I am done with it is showing tons of error while running the "dotnet run seeddata" command......... please help me

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

      what are the errors? please post github link and I will look

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

    Is onModelcreating method for many to many relationship only?

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

      It's for many things in general, but many to many relationships is one of them

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

    I'm hoping someone sees this but my build fails when i try to Add-migration i tried using -v but that didn't give me any useful info as to why it's failing

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

    I have issue when I run command dotnet run seeddata then it throw "System.ArgumentOutOfRangeException: startIndex cannot be larger than length of string." I don't know why. I try to repeat to see video and follow the code but not work. I still error when seed data. I can migration and update to database success

    • @user-dh2cf2vf2x
      @user-dh2cf2vf2x 10 месяцев назад

      make sure you add the "builder.Services.AddTransient();"

  • @anloncul8268
    @anloncul8268 6 месяцев назад

    I don't understand please help me with it:
    At the beginning we created a database. Then connected sqlserver with the pokemanreview db. when are are seeding you said there should be no database with same name and we saw in your server management there was no db. I assumed you deleted the pokemonreview database at some point. so what is the deal here? we should also remove the databse from server management app? I successfully add-migration but couldnt update-database? can you help me with that?

    • @TeddySmithDev
      @TeddySmithDev  6 месяцев назад

      Does the migration give an error? It should create with name in connection string but you will get error in console if no success.

  • @h4tt3n
    @h4tt3n 6 месяцев назад

    I really enjoy this series, but I can't get the connection string hack to work. When right-clicking the database and selecting properties, an empty window comes up.

    • @TeddySmithDev
      @TeddySmithDev  6 месяцев назад

      Might be time to update VS. if you can’t update, I would look into resetting settings to factory default. Never heard of this before 🤔

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

    I also had problems running Add-Migration. In the end I ran the app and fixed the errors, then it worked

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

      How did you solve this i am also having same error

  • @krofa6072
    @krofa6072 8 месяцев назад

    the tutorials are very awesome but the only problem I have is with the lack of explanation with seeding

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

    I am gtting error while adding migration itself, tried hard but couldnt find solution.....

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

    I've created the database and the seed as you shown. When I try to select the rows, the datas that should be there(seed), they're not :(

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

      does it produce error? your database context or settings .cs file is likely culprit

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

      @@TeddySmithDev don't worry, I rebuilt everything from zero and it worked! Thank you, you're Awelsome!

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

      don't forget to run the seeding commands from the terminal cuz I did and thought they ran automatically when u add migration and update the database

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

    I have reached video 5, and after installing the necessary packages, and also written the same code as yours. I am having this error when i run: Add-migration . The errors says Value cannot be null. Parameter('builder'). Please what should I do

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

    Can i skip the part of many to many relationship if my database doesn't have it?

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

    If you're using docker for whatever reason, your connection string may have the password show up as a bunch of *****. Just put in your actual password, should work out fine(if you've followed everything else properly that is).

  • @itsrino9851
    @itsrino9851 7 месяцев назад

    "you probably didn't need to know that" .... I did, i did need to know that. lol

  • @user-gp4bv6md8u
    @user-gp4bv6md8u 2 месяца назад

    sucessfully i am able to run my project but data is not get inserted in any table what could be reason for this can anyone please tell me

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

    Man, I'm getting an error on this last step. Does anyone know how to fix it?

  • @sahithshetty1035
    @sahithshetty1035 Год назад +4

    Didn't anyone get errors in the seed file. In the seed file provided in teddy's github link, there are firstname and lastname in the owner. But while creating the owner modal, we didnt include them. Did anyone did something about this?

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

      Yeah you need to change the Name to FirstName and LastName

    • @Michael-wi2ee
      @Michael-wi2ee Год назад +2

      Yeah you need to change it. And update the Review aswell. He integrated a public int Rating

    • @Console.WriteLine
      @Console.WriteLine Год назад

      Thanks guys ^

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

    I get this error -> The property or navigation 'Category' cannot be added to the entity type 'PokemonCategory' because a property or navigation with the same name already exists on entity type 'PokemonCategory'.

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

      You may have added the same property to the model

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

    sorry i coppy code file Seed.cs but it error with "review"

  • @HT-go2nb
    @HT-go2nb 5 месяцев назад

    How do i do this in VS Code? 2:45

  • @Kalliskivi63
    @Kalliskivi63 8 месяцев назад

    what is this "seed" use for ?
    i trying create different theme "not pokemon" but im stuck here
    idk what is that seed

    • @TeddySmithDev
      @TeddySmithDev  8 месяцев назад

      Seed = put fake data into DB so you can have something to work with

    • @Kalliskivi63
      @Kalliskivi63 8 месяцев назад

      @@TeddySmithDev i see, so i can skip that step right?

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

    When i run "Update-Database" command I got an error:The ConnectionString property has not been initialized.
    why is this error caused, how can i fix it.

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

      Did you fixed it i have the same error and if you did could you explain me too please

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

      same error

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

      if you did it teddy´s way, so make sure you reference the correct key from appsettings.json in your programs.cs. "DefaultConnection" is the key with your ConnectionString, so check options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")) is correct. could be a typo or your autocomplete, messing with you.

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

    Hi, Although I create the seed data in the same way, the database is created, all tables are coming, but the data in the tables are not. What could be the problem here?

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

      You might not have run “dotnet run seeddata”. Need to make sure to add seeddata.

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

      Hey Teddy, I did everything and it worked out perfectly fine. However, when I checked the data for each table everything was correct except the PokemonOwner table. The PokemonOwners have 0's on the PokemonId column but 1,2,3 on the OwnerId. What could be the issue? @@TeddySmithDev

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

    Maybe you will know the problem. I use AzureSQL and when I try to execute migrate I receive error:
    The SELECT permission was denied on the object '__EFMigrationsHistory', database 'master', schema 'dbo'.
    Currently still figuring out how to grant access to master. But still no hope.

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

      forgot to include category in defaultconnection heh. (dont use default aka master).

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

      You will prob have to go in and set the permissions in SQL

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

      @@TeddySmithDev Thank you for response, anyway, I just used default connection instead what I needed to do was define Catalog. When I defined Catalog= it worked fluently. Thank you for response.

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

    why we need that seed class plz someone explain how it works? do I need to do the same for my own projects?

    • @Mark-nm9sm
      @Mark-nm9sm 11 месяцев назад

      seed class is used to populate dummy data for your project. You dont really need it but if you want to test your API out then this is one way you could create ''random'' test data :)

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

    Hey, what's wrong with 'Pokemons' in plural? :) What other options?

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

      You can put Pokémons for DbSet. Won’t change anything but spelling. Slight possibility you might get invalid object error but then you just change the table name to what error is giving you.

  • @paudricsmith619
    @paudricsmith619 4 месяца назад

    Adopting a clear and intuitive naming convention for lambda parameters significantly enhances the readability and maintainability of your Entity Framework Core configurations. This approach ensures that anyone reading the code can quickly grasp the relationships between entities, making the codebase more accessible and easier to work with.
    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
    modelBuilder.Entity()
    .HasKey(pc => new { pc.PokemonId, pc.CategoryId });
    modelBuilder.Entity()
    .HasOne(pc => pc.Pokemon)
    .WithMany(p => p.PokemonCategories)
    .HasForeignKey(pc => pc.PokemonId);
    modelBuilder.Entity()
    .HasOne(pc => pc.Category)
    .WithMany(c => c.PokemonCategories)
    .HasForeignKey(pc => pc.CategoryId);
    modelBuilder.Entity()
    .HasKey(po => new { po.PokemonId, po.OwnerId });
    modelBuilder.Entity()
    .HasOne(po => po.Pokemon)
    .WithMany(p => p.PokemonOwners)
    .HasForeignKey(po => po.PokemonId);
    modelBuilder.Entity()
    .HasOne(po => po.Owner)
    .WithMany(o => o.PokemonOwners)
    .HasForeignKey(po => po.OwnerId);
    }