Getting Started with Entity Framework Core [1 of 5] | Entity Framework Core for Beginners

แชร์
ฝัง
  • เผยแพร่เมื่อ 21 ก.ย. 2024
  • Learn more ➡️ learn.microsof...
    Entity Framework Core is an Object-Relational Mapper that simplifies working with relational databases using strongly-typed .NET objects.
    Please note: At 4:08, the narration should state "Since FirstName and LastName are non-nullable strings, EF Core knows that when it creates the table, those two columns shouldn't allow nulls." We apologize for any confusion.
    How to code along with these videos: • How to code along with...
    Get the code and notes used in this series: github.com/Mic...
    Watch the entire series here: aka.ms/ef-core...
    Learn more about Entity Framework Core:
    Entity Framework Core: docs.microsoft...
    Getting Started with EF Core: docs.microsoft...
    GitHub Repo: Entity Framework: github.com/dot...
    Follow Cam Soper on Twitter: / camsoper
    Follow us:
    Twitter: / efmagicunicorns
    Facebook: / efmagicunicorns
    Blogs: devblogs.micro...
    Shows and Podcasts: docs.microsoft...
    Useful Links:
    Get your questions answered on the Microsoft Q&A for .NET - aka.ms/dotnet-qa​
    Learn .NET with free self-guided learning from Microsoft Learn: aka.ms/learndotnet
    .NET: dotnet.microso...
    Learn .NET: dotnet.microso...
    .NET Community: dotnet.microso...
    .NET Documentation: docs.microsoft...
    🙋‍♀️🙋‍♂️ Get your questions answered on the Microsoft Q&A for .NET: aka.ms/dotnet-qa
    🏫 Learn C#, F#, and .NET with free self-guided learning from Microsoft Learn: aka.ms/learndo...
    #DotNet #efcore #entityframework #beginner

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

  • @ryanford516
    @ryanford516 5 หลายเดือนก่อน +2

    Tried some 4 other EF tutorials today, had to deal with a ton of superfluous information while this one is straight to the point and just works. Thank you!

  • @andrewfionik1406
    @andrewfionik1406 ปีที่แล้ว +12

    This is brilliant. Simple. Straight to the point.

  • @yvesfree-assangescherdin6138
    @yvesfree-assangescherdin6138 ปีที่แล้ว +2

    A very good series of tutorial videos, but the last video contains useful tips about tools and materials that are relevant for all videos before (1-5), Everybody should watch video 6 first.

  • @peterburn2908
    @peterburn2908 ปีที่แล้ว +13

    Excellent video. I have reproduced all by myself and it worked wonderfully. Thanks a lot.😀

  • @jbob34345
    @jbob34345 ปีที่แล้ว +15

    Great video, a clear practical example. Thanks Sam!

  • @sevansam
    @sevansam 2 ปีที่แล้ว +29

    Alternative title: Darth Sidious getting you started with the dark side

  • @ic6406
    @ic6406 6 หลายเดือนก่อน +3

    I like how you selectively skipped ICollection populating part
    For those who don't know why does your ICollection empty, `.Include("CollectionFieldName")` syntax must be used when fetching an object

  • @WayneGreen-g8l
    @WayneGreen-g8l ปีที่แล้ว +1

    Thanks very much. Even though I've been using EF for a long time, there were still some things that I learned here and/or which got cleared up better.

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

    I rly appreciate for doing videos like this. You're helping me a lot.
    Take Care!

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

    Can't wait to see the rest episodes. 😃😃

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

    Amazing content! please keep on producing high quality knowledge.

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

    Let's go !!!

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

    What an excellent video! Including the .NET CLI instructions on top of the usual VSCode package manager was very helpful indeed, as I prefer vim/nvim over VSCode. Thanx a lot =D

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

    Simple and complet dekclaration! Very helpful! Thank you very much 🙏

  • @المرآة-ظ1ح
    @المرآة-ظ1ح ปีที่แล้ว +2

    Perfect

  • @Marco-qr8jb
    @Marco-qr8jb 2 หลายเดือนก่อน +1

    03:48 Why is it called an entity when its under a folder called "Models"? Is it a model or is it an entity? I am so confused.

    • @jecloyacosta5934
      @jecloyacosta5934 16 วันที่ผ่านมา

      Entities represent tables in the database and are used to map the database schema using a class. Each instance of an entity corresponds to a row in the database table.
      On the other hand, a model is any class that represents data within the application. Models are used for various purposes, such as displaying data, transferring data, or encapsulating domain logic.

  • @HectorRodriguez-hr9tf
    @HectorRodriguez-hr9tf 7 หลายเดือนก่อน

    Simply: Great!
    One of the best tutorial I've ever seen!...Clear and to the point!

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

    you save my job, thnks

  • @do-electronics
    @do-electronics 2 ปีที่แล้ว +10

    Error CS0053 Inconsistent accessibility: property type 'Customer' is less accessible than property 'Order.Customer' 5:00
    The solution is to remove public modifier of declaration.

    • @ahmedfattal9569
      @ahmedfattal9569 2 ปีที่แล้ว

      No! All you need is to make sure the Packages are 6.0.4! I had many problems using 6.0.8

    • @ДенисГовдиш
      @ДенисГовдиш 2 ปีที่แล้ว

      @@ahmedfattal9569 and how did you fixed that?

    • @ahmedfattal9569
      @ahmedfattal9569 2 ปีที่แล้ว

      @@ДенисГовдиш Install 6.0.4 instead of newer ones

    • @tiem217
      @tiem217 ปีที่แล้ว +3

      No if you change the product class from internal to public it should work

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

      or move it into the same assembly and declare everything there as internal.

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

    Very nice, but without experience in database programming the user has no chance of understanding what is happening. So it's not for beginners at all, but for EF Core beginners ;-)
    How I can connect to a MySQL database?

  • @mikeafter5
    @mikeafter5 2 ปีที่แล้ว

    Thank you for posting these.

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

    for those who are having an error on connecting the server, because it says its not trusted, you have to write this in the connection string:
    --------------TrustServerCertificate=true;--------------------

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

    The tutorial is great. But guys be advised you need different packages if you use MySQL and not SQL like in this tutorual. Coz I'm a noob at this and spent the whole day trying to figure out why i can't connect to the DB.

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

    Thank you

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

    Awesome explanation

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

    Thank you very much ! Great teaching !

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

    Absolutely brilliant video tutorials! Subscribed!

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

    I'm typing out every cs file since they are not in github files as far as I can see. Any ideas? By the way, I wrote this same comment yesterday and it's not here now. I suppose it got deleted?

  • @tombaxter2879
    @tombaxter2879 ปีที่แล้ว +2

    Nice job. Well done.

  • @WayneGreen-g8l
    @WayneGreen-g8l ปีที่แล้ว +1

    Why doesn’t the class Product have an ICollection OrderDetails {get; set;} the way the class Order has it?

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

      If you need to retrieve all order details for this order, you can do that. It is, however, not needed for this tutorial

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

    Excellent video. Thanks bro!

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

    Its simple and clear, Can I find more advanced tutorials on this please.

  • @williamstobi9424
    @williamstobi9424 ปีที่แล้ว +2

    when I try to update database I get this error
    A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - The certificate chain was issued by an authority that is not trusted.)

    • @scfnukasystemofcare
      @scfnukasystemofcare ปีที่แล้ว +3

      You might try adding "TrustServerCertificate=true;" to the connection string.

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

    Well done!

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

    thanks, helped me a lot!

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

    Excellent. Question: Would it work with postman?

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

    Excellent video

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

    when I try the command Update-Database i get the 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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
    how can i fix it

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

    I really wish we could use EF Core but as far as I know, it does not support the database my company is stuck using - IBM for i or DB2 iSeries (or whatever it’s called these days).
    To make it worse we are stuck on version v5r4! 😢
    Does anybody know if EF Core can be used for this as I haven’t been able to find anything for years.

  • @thanosmrk
    @thanosmrk 2 ปีที่แล้ว +2

    0:50 "Each order detail contains a product and quantity"
    The connecting line on the diagram is many-to-many. Is it wrong?

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

    This is lovely

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

    Is this still relevant for someone starting with .NET 8 and VS2022.... I think I'll use Dapper for some SQL interface as I like to see what's happening under the hood (I have good SQL skills) but the whole migrations/class building and/or database updates seem ideal for EF plus perhaps the basic CRUD operations.

  • @rmurphy440m
    @rmurphy440m ปีที่แล้ว +3

    So we have to manually do all the work that the older EF implementations did for us via the diagrams.
    Got it.

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

    Wow Good video, Thanks a lot ^^

  • @AliHazrat-cm8hq
    @AliHazrat-cm8hq 4 หลายเดือนก่อน

    Isn't the relationship b/w OrderDetail and Product must be 1-M ? OrderDetail is actually a Gerund (aka Associative Entity)!

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

    May I know what is the difference between the followings in the model:
    [Required]
    public string? Name {get; set;}
    public string? Name{get;set;}
    public string {get; set;} = null!

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

      i hope you already know the answer, but ill just leave it here in any case:
      public string? Name{get;set;} -> null can be assigned to this property and nothing happends
      public string {get; set;} = null! -> null CANT be assigned to this property but with this " = null!" you say to the complier that you are aware about it and possible risks such as null ref exception ecc.
      [Required]
      public string? Name {get; set;} -> does not make a lot of sense actually... [Required] attribute is used to indicate that a property must have a value and cannot be null. However, when you use the string? syntax, it already indicates that the property can be null. so its better to use [Required] with the first example if you want to enforce the non-null requirement for a string property,

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

    Do I have to setup SQL-Server and making tables
    before to do this ?

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

    when i do the Add-Migration InitialCreate and Update-Database i dont see the database on the Sql Server object Explorer any help ??

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

    great tutor ❤

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

    What do you mean by use a secure storage method for real world connection? Which other method do you mean? Thanks.

    • @BJJsancin
      @BJJsancin ปีที่แล้ว +2

      You would want to read this value from something like azure key vault. Either that, or a configuration file at the very least.

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

    Good Video, but I have one question, when I try the command Add-Migration, I get the failure, that Android will not be supported. So I tried to make a DummyProject, like the documentation says, but it doesn't work... Can someone help me?

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

    Why is it when we remove we don’t interact with the DBSet ?

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

    In this context, I keep getting an error with the update database.
    A network-related error or an instance error was detected.
    I have now managed to get the database visible in SQL Server Explorer, but when I run Update-Database I also get a long error message with this note: A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - The certificate chain was issued by an untrusted certificate authority).
    Can anyone tell me how to solve this? Maybe renew the certificate, etc.?

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

      "ConnectionStrings": {
      "YourConnectionString": "Data Source= blablabla ;TrustServerCertificate=True;"
      }

  • @RomuloMagalhaesAutoTOPO
    @RomuloMagalhaesAutoTOPO 2 ปีที่แล้ว

    Thank you very much.

    • @camsoper7902
      @camsoper7902 2 ปีที่แล้ว

      You're welcome! 😊

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

    Does add migration removes the previous tables and data? What if table already has data and I have to add a new column. Would it delete the data?

    • @WhatIsBinary
      @WhatIsBinary ปีที่แล้ว +2

      Yes it would delete whatever you removed from the model. It is essentially creating a new instance of whatever exists in said model, not just adding what is new to the model.

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

    Any plans to explain relationships like hasmanythrough or pivots?

  • @User.2024.1
    @User.2024.1 6 หลายเดือนก่อน

    How is EF Core [8] different from .Net [8] ??? I'm really confused. I couldn't find any comparison on the internet or even on MS website.

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

      they are both different things, .net 8 its a version of a whole c# library, EF Core its a framework used to manage data more easily, its like SQL but converted in C# language.
      if im wrong someone correct me pls, but i think thats basically it.

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

    Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : Login failed for user 'SA'.. Does anybody know why that happens every time I'm trying to connect to sqlserver? I'm on macOS and using a container for the database and I've used both connection strings Cam has provided. Nothing has worked so far.Thanks

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

    That tool bar in the bottom, how can I set it up in my VS?

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

    hello, thanks for the video. I've a question. How can I create those tables in another DB in my local server, letsay the name of the Database is DiscApp. Thanks

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

    IS it possible to use EF Core InMemory for CosmosDB ?

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

    Getting this error on update-database command on my local sql server
    A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - The certificate chain was issued by an authority that is not trusted.)
    Please help

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

      Put "TrustServerCertificate=true;" in the connection string

  • @ysfarslanon
    @ysfarslanon 2 ปีที่แล้ว

    What is the our approach in this video? Code first or Model first.

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

      it's code first method

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

    I have been following the tutorial. I need some help regarding a query on how to get data from two tabels where second table has foreign key from first table?
    I tried few Linq but ended up getting error of datareader being open

    • @camsoper7902
      @camsoper7902 2 ปีที่แล้ว +3

      Go to the GitHub repository in the description. The project in Part 5 does what you're asking in parts/5-performance-tips/ContosoPizza/Pages/Customers/Details.cshtml.cs line 32

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

    why is he not using brackets in the using block?

    • @camsoper7902
      @camsoper7902 2 ปีที่แล้ว +2

      The syntax I use in the video disposes of the object when it falls out of scope. Same thing as with the brackets, just simpler.

    • @do-electronics
      @do-electronics 2 ปีที่แล้ว

      Where ?

    • @kavkavy
      @kavkavy 2 ปีที่แล้ว

      @@do-electronics 11:15 when declaring the context

  • @KarthikS30712
    @KarthikS30712 8 หลายเดือนก่อน +12

    Hi Cam Soper. This isn't really a "for Beginners" playlist. There are so many things not described here. What are migrations and why did you create them? I have to pause/leave this video and go somewhere else. And that place throws me off into a different tangent. Why doesn't Microsoft respect developer's time? It's not funny, it's insulting.

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

    has anybody tried this on macOS?

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

    is it possible to use this for macOS?

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

      Yes, I am developing on macOS, Visual Studio 2022 with Entity Framework Core. I hope this helps.

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

      @@MulkRaj101 Cam you connect to SQL Server cause I've tried everything but I can't

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

      @@younesmdarhrialaoui643 I am using SQLite.

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

    Great video. Just that I wish i could see how the solution was set up. It shows its a Console app not much how to set up

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

    Are you sure your name is not meant to be Sam Cooper

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

    This is not for beginners ...

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

    did not show how to do a connection string terrible

  • @runtimmytimer
    @runtimmytimer 2 ปีที่แล้ว +5

    This database will perform like 💩in a high volume production environment. If you look at the migration generated, all string columns translate to a NVARCHAR(MAX) data type. NVARCHAR(MAX) will absolutely kill your database server performance. This is one of the many gotchas in EF. You must annotate all string properties in your classes to set maximum lengths if you plan to do a code first approach. EF is a great tool but it's really easy to shoot yourself in the foot in production environments. Use with caution.

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

      u can change the NVARCHAR(MAX) to any number u want , data annotations are old and useless, EF Core is powerful in the right hands.

    • @zweisser
      @zweisser 2 ปีที่แล้ว

      u know that this is a entry-level tutorial which does not address performance, right, dip💩 ?

    • @mzg147
      @mzg147 2 ปีที่แล้ว

      @@fadidib8516 Why data annotations are old?

    • @Rubicon43
      @Rubicon43 2 ปีที่แล้ว

      Why do you say that. The VAR in NVARCHAR means it contains the length. Do you have any evidence to support your claim? What you assert is a common myth.

    • @fadidib8516
      @fadidib8516 2 ปีที่แล้ว

      @@Rubicon43 isn t a DB either a Var or a Nvar just different length and type of ANSII or UTF8

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

    help

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

    Create tables automatically ? This is absolutely ridiculous. In the corporate world the DB is always created separately and very carefully.
    this technology may be suitable to use in very small systems. NEVER will be accepted In the corporate world.
    ORM is like: technology for children. :)

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

      Someone's regretting sinking years of their life into learning SQL...

  • @nunocamarinha
    @nunocamarinha ปีที่แล้ว +3

    I am sorry, but this just made my blood boil... i cannot agree with this type of approach. if the intention is to create a "for beginners" series, core concepts should be introduced first instead of just typing s***t away (in this case paste). Julie Lerman needed a couple of books to explain this framework properly: Code first, database first, annotattions, linq to entities, linq to objects, change tracking, concurrency handling, etc etc. the dbcontext class alone gets an entire book dedicated to it... no one really learns anything with this type of video, but they may be fooled to think that they did.

    • @michaelsnead8725
      @michaelsnead8725 ปีที่แล้ว +2

      On the contrary... It was exactly what I needed. It got me up and running really quickly and I didn't have to read a s***t load of books which would cause me to fall asleep and never really get started. I have work to do and just want something that works. (I've been a software engineer for over 40 years and really wanted to get to know the latest EF... which I am a "beginner" at. Finally, something that is good, to-the-point, and, frankly, I can understand the English without dealing with an accent. There are so many (well meaning) people out there that are making videos which are not understandable to me, due to the very heavy accents. I know the content is good, but I never can follow it comfortably. I really, really needed this.

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

    Lots of technical mistakes. You are going to confuse a lot of people. You should have someone more technical review the video before you post it. If they are just you mis-speaking, you should review your own video before you post it. Corrections should go in the video as annotations, not in the notes. People don't read the notes.

  • @on4ayl
    @on4ayl 2 ปีที่แล้ว

    Too small to see.

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

      I'm sorry, I tried to make sure it was a good balance of large enough to read and small enough to make good use of pixels. I recorded it at 1080p and I had the Windows 11 DPI settings set to 120%. I'll try to do better next time!

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

      Just zoom in. It's 100% way better than any EF videos on the web.

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

      @@camsoper7902 You did it right. It's perfectly visible. on4ayl just needs to hit the fullscreen button.

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

    @dotnet