Entity Framework Core Part 7 - Models vs Entities

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

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

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

    There's still lots more to EF Core. Let me know what you want to see.
    Source code is at github.com/JasperKent/EntityFramework-Models-vs-Entities
    Subscribe for the rest of the series at: th-cam.com/channels/qWQzlUDdllnLmtgfSgYTCA.html
    And if you liked it, click 'like'!

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

      Excellent, well explained video. Might other people call the "BookModel" a DTO? Thanks.

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

      @@iancarr3923 Yes a DTO - Data Transfer Object - is very similar to a model, but particularly when it's being used to send data over a network.

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

      @@CodingTutorialsAreGo Many thanks for such a quick reply. It has helped my ageing brain!

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

    Latest version of EF by default recognises that you have renamed the column and the migration produced calls the RenameColumn method. But great to know that it didn't used to be like this. Keep the videos coming 👍

  • @TrotterSoccer
    @TrotterSoccer 26 วันที่ผ่านมา +1

    Nice series of videos on EF Core. Well presented. Thanks.

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

    I am getting clear picture of ef core. Thank you for sharing you knowledge with us

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

    Great work. I haven't seen many as detailed and providing a such thorough information about technology for beginners videos as that one. I found it really interesting. Keep it up!

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

    This is the best EF video ive ever watched ! Thank you 💯

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

    I have found my new role model!
    Really appreciating your explanations.

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

    Thanks for all of your videos...you are teaching step by step, helps me better understand logic and how things work...to let you know, I would like to see how to create model implementing SelectListItem, Searchbox, and some additional features that website can offer to user and the way new data is generated by user into existing columns...sort of speak, the opposite way :)

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

    Awesome tutorial, and great appreciation to you guys producing the amazing video!

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

    This a great way of explaining it.

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

    Thanks a lot for a good and understandable video! 👌

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

    Thank you for this series. I would love a full C# web API tutorial but I know that's probably a big ask!

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

      Glad you liked it. I haven't done much on WebAPI, but I'll try to get round to it. I'll break it down into small chunks like this one.

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

    Hi, in Author class you use virtual ICollection Books property. But previously you told that virtual keyword adds onlt overheads for eager loading. Or I've missed something?

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

      That's correct. You only need virtual if you're doing lazy loading, which is generally a bad idea. For eager loading you don't need it. In any circumstance, using virtual adds a very slight overhead, so should be avoided if not needed. I can't remember why I included it here.

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

      @@CodingTutorialsAreGo Thank you for the answer :)

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

    Very good video sir thank you for your effort :)

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

    Does the extension method have to return an Iqueryable? Does it have better performance than an Icollection?

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

      ICollection isn't derived from IQueryable, only from IEnumerable, so you'd have to execute the query with ToList or ToArray to convert it. That would mean if you did any further filtering it would be done in memory not in the database. So yes, it is a performance issue. See th-cam.com/video/fvzuMVPlc6Y/w-d-xo.html

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

    Thanks you!
    What about DTOs ?
    Can you use it in place of mvc model then use mvvm for view model ?
    Use the auto mapper to map the entities to the dtos for mvc ?

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

    What happens when you have another shape of the model class that is maybe more concise or something. like say you have a second version called BookModel2 that is used by a specific view where is all of this mapping logic stored?

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

    I have a question.. In what layer of the application would you put this BookModel class?

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

    Great video, is there anywhere where i can learn more about that static extension method? IQueryable ?
    I would like to get a better idea of how using (this IQueryable) in this method extends the IQueryable object.
    And if in this case shouldn't this be an extension to Book, or even IQueryable rather than on bookmodel? this function cannot be applied to a BookModel, right?
    Thanks

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

      There's a general discussion of extension methods here: th-cam.com/video/xzlNv737xBM/w-d-xo.html
      The specific thing about extending IQueryable is that Entity Framework analyses the code we put in there and generates the appropriate SQL when the query is issued.
      Notice that we are extending IQueryable (the entity) not IQueryable the model, because we're using this to map a collection of Books onto a collection of BookModels.
      However, I have put it in the BookModel.cs file, rather than the Book.cs file. That's because, as a general rule, Models should be dependent on Entities, not the other way round. If the extension method were declared in Book.cs, then we'd have to have a reference from BookLibrary to EFCore, which would be wrong.
      I could have put the extension method in a file on its own, but it seems to me very closely associated with BookModel, and putting in BookModel.cs doesn't create any dependency issues.
      Hope that helps.

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

      ​@@CodingTutorialsAreGo Yes!
      This is very clear, i just got confused because of the name of the class being BookModelExtensions, just because it doesn't really extend BookModel.
      Since i wasn't familiar with the way of extending classes yet (learning in process) i was trying to wrap my head around how that method extends BookModel.
      Now i know that the name BookModelExtensions is named that way because it is an extension that COMES WITH BookModel rather than being an actual extension of BookModel as such.
      Hope i got it correctly now hehe

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

      Very good point.
      When it comes to extension methods, the name of the they class they are declared in is pretty much irrelevant. That class name is never used anywhere else in the code except for the declaration.
      You're absolutely right that in choosing that name I was subconsciously thinking 'an extension that comes with BookModel', but I hadn't made that clear.

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

      @@CodingTutorialsAreGo Not to worry, it created a new opportunity to learn ;) thanks for the replies!

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

    In .NET 7, when rename the column, we don't loss any data in this column without changing the code in Migrations folder

  • @patrickha7541
    @patrickha7541 3 ปีที่แล้ว

    Thank you for this, very helpful!

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

    Great Video. Thank you!

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

    Great Video !
    Do you have Roles tutorial videos?

    • @CodingTutorialsAreGo
      @CodingTutorialsAreGo  3 ปีที่แล้ว

      Do you mean as in the Role Object pattern? Or as in roles with authentication and authorization?

    • @thuyuyenlovely8053
      @thuyuyenlovely8053 3 ปีที่แล้ว

      i want to say about Roles with Authentication and Authorization in .net core.
      your video EntityFramework tutorial is very easy to understand . thanks so much !

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

      I'll put it on the list.

    • @thuyuyenlovely8053
      @thuyuyenlovely8053 3 ปีที่แล้ว

      @@CodingTutorialsAreGo
      I shared link Entity Framework core tutorial video on Group Facebook Net core
      and a lot of people like it.
      i hope you can create a lot of courses
      thanks

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

    oh man finally ! thank you

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

    wow ty sir.
    you are awesome

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

    I am naming my "view models" dto (data transfer object ) what is your thought on this sir ?

    • @CodingTutorialsAreGo
      @CodingTutorialsAreGo  3 ปีที่แล้ว

      It's certainly quite common to call them DTOs, though the term is very general and therefore can be overused, which may cause confusion. Typically (though it various from one company to another) I would reserve DTO for when I'm writing a Web API and we're actually sending data over the wire to the client. Here, the data is staying with in the server application and just moving from the controller to the view, so it's not really being 'transferred'. That said, as long as you and your colleagues are all using the same terms and understand them, it doesn't much matter.

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

    I can't call ToModel() from Books context

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

      Not sure what to say. I works in the code provided, so I guess you've changed something.

  • @ohaRega
    @ohaRega 3 ปีที่แล้ว

    Thanks!

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

    Thank you for your efforts I love it. But as a PHP Laravel developer I feel that making so much files in c# makes the code confusing with no real benefits.
    Why we need to make a class for entity and a class for model as the deference is not that much. This is what I don't like about c# and .net environment generally, they make so much confusing terms that is not needed in so many situations and might be needed only in specific situations. This mainly make the code more complex and big.
    For example in Laravel some times you will not add to model any extra code just few lines to write the model and that's it you can use then any place.
    I am not saying that c# is not good but I feel that it is so much of code most of the time ... less code is better code

    • @DaveRoman-mc4nn
      @DaveRoman-mc4nn 2 ปีที่แล้ว

      The terms entity and model have nothing to do with C# and .NET, they are generic terms. You can apply whatever terms you want. If you don't like to create a file per entity, don't do it, nobody is stopping you.
      Normally you create files for each thing because it is more maintainable in the future and it makes your code more orderly and this is something that can be applied in any technology, not only in .NET/C#.
      And regarding your last paragraph, it's not entirely true, less code will not make your code better. By trying to make less code you can write something unmaintainable.

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

    Horrible solution. But that is what you get using EF.
    Don't use EF, use ADO.

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

      Sorry Couldn't get you.
      Please can you elaborate on why we should use ADO and not EF ?

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

      @@LineshLanjewar because EF is based on ADO.
      EF is just an extra layer on top of ADO. Making things slower, complicated etc.
      It is a matter of " loose the middle man"

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

      @@wiepcorbier Ohkay. Thanks for the info.

  • @elias.clsn.92
    @elias.clsn.92 ปีที่แล้ว +1

    Amazing video! Thank you