Entity Framework Core Part 7 - Models vs Entities

Поділитися
Вставка
  • Опубліковано 1 лют 2025

КОМЕНТАРІ •

  • @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: ua-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!

  • @TrotterSoccer
    @TrotterSoccer Місяць тому +1

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

  • @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 👍

  • @dheerajambippi2283
    @dheerajambippi2283 3 роки тому +2

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

  • @sakshock
    @sakshock Рік тому +1

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

  • @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!

  • @demi9672
    @demi9672 3 роки тому +1

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

  • @thedude6810
    @thedude6810 Рік тому +1

    This a great way of explaining it.

  • @TigerCat618
    @TigerCat618 3 роки тому +1

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

  • @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 :)

  • @teto3252
    @teto3252 2 роки тому +1

    Thanks a lot for a good and understandable video! 👌

  • @johnyw1049
    @johnyw1049 3 роки тому +1

    wow ty sir.
    you are awesome

  • @nick11927
    @nick11927 4 роки тому +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  4 роки тому +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.

  • @niroshanmanoharan4295
    @niroshanmanoharan4295 4 роки тому +1

    Great Video. Thank you!

  • @armanx2
    @armanx2 3 роки тому +1

    Very good video sir thank you for your effort :)

  • @patrickha7541
    @patrickha7541 3 роки тому

    Thank you for this, very helpful!

  • @ThemisTheotokatos
    @ThemisTheotokatos 3 роки тому +1

    oh man finally ! thank you

  • @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: ua-cam.com/video/xzlNv737xBM/v-deo.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!

  • @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 :)

  • @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

  • @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 ?

  • @ohaRega
    @ohaRega 3 роки тому

    Thanks!

  • @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 ua-cam.com/video/fvzuMVPlc6Y/v-deo.html

  • @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

  • @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?

  • @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 3 роки тому

    I can't call ToModel() from Books context

    • @CodingTutorialsAreGo
      @CodingTutorialsAreGo  3 роки тому

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

  • @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