EF Core Many to Many relationships

Ғылым және технология

EF Core many to many relationships are a little bit trickier, since we can't solely rely con conventions. Still there are only two steps that you have to be aware of when configuring a many to many relationship using EF Core:
1. Add an entity class for the relationship
2. Define two one to many relationships in the OnModelCreating() method of your DbContext class.
In this video we get through all the needed steps, so after watching it you'll get the hang of many to many relationships in EF Core
#efcore #dotnetcore

Пікірлер: 50

  • @robsonfaxas
    @robsonfaxas3 жыл бұрын

    Thank you so much! Well explained even for a Brazilian guy like me, who has English as a secondary language.

  • @mrsco006
    @mrsco0063 жыл бұрын

    One of the best videos explaining this! I’m using it to help build an iOS PassKit web service. The many to many requirement of the Device and Pass seem to map nicely to Author/Book. Thanks!

  • @Codewrinkles

    @Codewrinkles

    3 жыл бұрын

    Glad it helped!

  • @mrsco006

    @mrsco006

    3 жыл бұрын

    @@Codewrinkles ya I’m pretty much finished with the project now. Thanks again!

  • @Gnomecannibal
    @Gnomecannibal2 жыл бұрын

    Thank you so much for the video

  • @lordmemes9808
    @lordmemes98082 жыл бұрын

    DUDE !!! YOU SAVE MY LIFE!!

  • @Codewrinkles

    @Codewrinkles

    2 жыл бұрын

    Glad to hear that :)

  • @lordmemes9808

    @lordmemes9808

    2 жыл бұрын

    @@Codewrinkles Love you man, keep up the good work. I have wasted a lot of time trying to figure this out, thank you so much

  • @xSAxHellboy1
    @xSAxHellboy13 жыл бұрын

    Great video helped me with school thanks

  • @Codewrinkles

    @Codewrinkles

    3 жыл бұрын

    Glad it helped!

  • @zaidmasri9026
    @zaidmasri9026 Жыл бұрын

    Any advice on how you would set this up using DDD?

  • @RomanNorman
    @RomanNorman Жыл бұрын

    Great content, love the passion

  • @Codewrinkles

    @Codewrinkles

    Жыл бұрын

    Hopefully you watched also the most recent videos. There's even more passion!

  • @itznukeey
    @itznukeey3 жыл бұрын

    Thank you helps alot

  • @mbungopaulo
    @mbungopaulo2 жыл бұрын

    Hello Sir, i liked your video, you explained well the content and you took away all my doubts :-)

  • @Codewrinkles

    @Codewrinkles

    2 жыл бұрын

    Glad to hear that. Fortunately, starting EF5 everything is easier as many to many relationships are also created by convention.

  • @ramimuddin7925
    @ramimuddin79253 жыл бұрын

    Hello Sir, I have followed your tutorial and configured the many to many relationship via the Model Builder. Now I have a problem, how can I perform the CRUD queries in C#? I get an error in the intellisense saying that I cannot convert from a class model to a class join model (for example, cannot convert from Movie to MovieWatchList). Do you have tutorials covering this? Please I need help.

  • @dyaaCoding

    @dyaaCoding

    11 ай бұрын

    have you figured it out?

  • @ramimuddin7925

    @ramimuddin7925

    11 ай бұрын

    @@dyaaCoding honestly I can’t remember, it was quite a long time ago

  • @dahliaspumpski5837
    @dahliaspumpski58373 жыл бұрын

    Your music didn’t bother me I found your video very helpful after watching your one to many relationship video. Thank you

  • @Codewrinkles

    @Codewrinkles

    3 жыл бұрын

    Glad it was helpful!

  • @chezchezchezchez

    @chezchezchezchez

    3 жыл бұрын

    LOL funny stuff

  • @mensiuscho
    @mensiuscho Жыл бұрын

    Very very good, Thanks a lot

  • @Codewrinkles

    @Codewrinkles

    Жыл бұрын

    Most welcome

  • @AmNotLegend
    @AmNotLegend Жыл бұрын

    super clean and time-saving, although I m using java, it makes sense to me

  • @Codewrinkles

    @Codewrinkles

    Жыл бұрын

    Glad you liked it. The Java and DotNet ecosystem have a lot of things in common.

  • @DavidJames535
    @DavidJames535 Жыл бұрын

    how to query the table book and author ?

  • @SkuezTech
    @SkuezTech2 жыл бұрын

    Am I missing something? Is this how this was done before? Anyhow, nowadays just put ICollection on both classes and entity fc will handle everything else

  • @Codewrinkles

    @Codewrinkles

    2 жыл бұрын

    Yes, things have changed in EF 5 (EF Core 5). To be honest, it's a total mess with different EF versions. For instance on EF for .NET Framework many-to-many relationships are configured by convention (as you said) for quite a few years. However, in EF Core this was never possible and you would need an object for the joining table and configure the relationships manually. In EF Core as part of .NET 5 many-to-many relationships by convention was one of the most expected features. Together with the DbContextFactory useful for Blazor Apps and deskop apps (yes you can create .NET COre WPF apps)/

  • @user-oq9kn8zd2y
    @user-oq9kn8zd2y2 жыл бұрын

    Thanl your for the video. But I still have one question. How to update. Can you explain to me how to with update many-to-many relatinship tables?

  • @Codewrinkles

    @Codewrinkles

    2 жыл бұрын

    Here's a brand new video that might help answer this question: kzread.info/dash/bejne/nIKLj9d8gNCvcrg.html

  • @chadmerdinger2418
    @chadmerdinger2418 Жыл бұрын

    Can this very same approach be used to define triple many to many to many relationships?

  • @Codewrinkles

    @Codewrinkles

    Жыл бұрын

    Not sure exactly what you mean, but I guess the answer is yes. An entity can be involved in several many-to-many relationship at the same time.

  • @chadmerdinger2418

    @chadmerdinger2418

    Жыл бұрын

    @@Codewrinkles what I mean is the following, for example, in a shopping app there is an Order entity, which can contain many Products (which consists of 1 product), Bundle (which consists of multiple products, but is coded as a separate entity and an order can contain many bundles in it), and let's say an entity named DiscountCode contains discount codes the user can use to get discount for an order (can use multiple codes per order), making the Order entity result of a many to many to many relationship. What I mean is, can this technique be used to create such entities? Sorry if the example mentioned is not the best, I just thought of it on the fly...

  • @AnkitYadav-kz2ei
    @AnkitYadav-kz2ei10 ай бұрын

    Hello sir, How will i seed data in These table using EFCore i am facing difficulty in this many to many relationship. kindly suugest .

  • @Codewrinkles

    @Codewrinkles

    10 ай бұрын

    I think this video might have the answers you are looking for: kzread.info/dash/bejne/aGqJz7qtmdjIaZM.html

  • @AnkitYadav-kz2ei

    @AnkitYadav-kz2ei

    10 ай бұрын

    @@Codewrinkles Thank you !!

  • @BigyanChap
    @BigyanChap3 жыл бұрын

    plz get rid of background music on your upcoming videos

  • @Codewrinkles

    @Codewrinkles

    3 жыл бұрын

    Is the background music so bothering?

  • @chezchezchezchez

    @chezchezchezchez

    3 жыл бұрын

    @@Codewrinkles yes! It’s terrible. How did you come up with such a dumb idea?

  • @ceedeeb

    @ceedeeb

    3 жыл бұрын

    These guys are very alone in their views. Background music 100% is fine and good.

  • @ramimuddin7925

    @ramimuddin7925

    3 жыл бұрын

    @@chezchezchezchez the music is not the problem, is your pathetic level of attention to the guys explanation, he’s even speaking loudly and everything is clear

  • @ramimuddin7925

    @ramimuddin7925

    3 жыл бұрын

    He doesn’t have to, as the explanation is clear

  • @rockroks629
    @rockroks6293 жыл бұрын

    Hello Sir, I have followed your tutorial and configured the many to many relationship via the Model Builder. Now I have a problem, how can I perform the CRUD queries in C#? I get an error in the intellisense saying that I cannot convert from a class model to a class join model (for example, cannot convert from Movie to MovieWatchList). Do you have tutorials covering this? Please I need help.

  • @Codewrinkles

    @Codewrinkles

    3 жыл бұрын

    Can you post the code of what you are trying to do?

  • @Codewrinkles

    @Codewrinkles

    3 жыл бұрын

    @@ramimuddin7925 I'm really sorry I missed your question. As it is the same, my previous reply also applies to you. Could you post the code that showcases what you are trying to achieve?

  • @ramimuddin7925

    @ramimuddin7925

    3 жыл бұрын

    @@Codewrinkles no problem sir. I actually found a way to sort it out. Hopefully, everything is working but is still a bit annoying that there’s no documentation explaining how to handle and query many to many relationships. Maybe that might be a new content to create for your channel 😊

  • @ramimuddin7925

    @ramimuddin7925

    3 жыл бұрын

    And please ignore my previous reply, it seemed rude, it wasn’t directed to you but to someone who doesn’t even know how to put a proper sentence in plain English. Anyway thanks for your reply and please keep making content. It is really helpful 👍🏽

  • @Codewrinkles

    @Codewrinkles

    3 жыл бұрын

    @@ramimuddin7925 No problem. I'm just trying to help. A video on working with many to many relationships is now on my to do list :). However, I can't estimate a timeline since these weeks I'm fairly busy with work and personal stuff.

Келесі