ASP.NET Core Web API + Entity Framework Core : Saving Related Data - EP05

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

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

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

    Code - github.com/CuriousDrive/BookStores
    Thanks for watching, please share with your friends :)

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

    Hello Fahad, I am glad to be the first one to congratulate you for the new Episode
    Please keep on the excellents tutorials.
    BTW. I was stuck on how to save related data and now you guided me on that.
    Thank you soooooo much indeed.

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

    I just wanted to Pause to thank you for what for this absolutely fantastic series! Just completed ep 4 and I have learnt so much! So I wanted to break to thank you! Thank You so much and really appreciate the care in your explanations and you also remembering to include your extra note and sql data... in the repo.
    Thanks Again!!!

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

      Hey Fumz, Thanks for lovely feedback. I remember talking to you in Twitch too :).
      I have added the query which can generate schema and data for you to work. Please check out this below link
      github.com/CuriousDrive/BookStores/blob/master/Database/GenerateData.sql

    • @shollymore
      @shollymore 4 ปีที่แล้ว

      @@CuriousDrive yes that was me the other day. Since I had a twitch account I thought to also subscribe on there my surprise you were live when I landed on your page... 😊

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

    Thank you for an easy to follow example. I have subscribed to your channel!! :-) - And thank you for sharing code, so it easy for other to see the details in the examples! Great work!

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

      I am glad that you are finding these tutorials useful. Thanks for subscribing Esben.
      Please share with your friends too :)

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

    thank you so much from the hearth you have solved a big problem to me with relationship between tables, you are opoened many door to me

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

      I am so glad that I could help you out. Please subscribe and share videos with your friends :)

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

      @@CuriousDrive yes of course my friend

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

    Hi Fahad. Great work brother.

    • @CuriousDrive
      @CuriousDrive  4 ปีที่แล้ว

      Thanks for watching Ahmed. Please share with your friends

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

    Excellent Video

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

    Really great tutorial

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

      Thanks for watching Anirudh :)

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

    Very nice tutorial but would like to know how does update works for related data

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

    Tutorial is very good. Are there any new series on .Net 6/7/8/ Web api??

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

    thanks for creating such great tutorial
    in you create tutorial for asp.net core web forms also.

    • @CuriousDrive
      @CuriousDrive  4 ปีที่แล้ว

      CodingFacaulty, .NET team stopped supporting web forms in 2019. They have moved on to Razor Pages, MVC and Blazor.

  • @JuanM-ck4jg
    @JuanM-ck4jg 3 ปีที่แล้ว +2

    How can I add a created book to one new sale? Please help me :(

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

      Sale class has Book as property so I would first create a new object of Sale and then create new object of Book and assign that Book to Sale's Book property. And then insert sale. Both should added in the database. I hope I answered your question.

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

    Boa noite meu amigo, tenho uma uma duvida com relação ao UPDATE. Quando faço o UPDATE não atualiza as entidade "Filhas". Tenho que fazer o update separadamente, tabela por tabela ou tem alguma forma de fazer igual ao create que gera o id para as tabelas filhas?
    var avoidingAttachedEntity = await GetByIdAsync(obj.Id);
    dbContext.Entry(avoidingAttachedEntity).State = EntityState.Detached;
    var entry = dbContext.Entry(obj);
    if (entry.State == EntityState.Detached) dbContext.Attach(obj);
    dbContext.Entry(obj).State = EntityState.Modified;
    return await dbContext.SaveChangesAsync();
    Atualmente meu repositorio de update esta assim, porém tenho que atualizar tabela por tabela.
    Obrigado e continue com os vídeos, você é melhor do que muitos professores aqui do Brasil. Grande Abraço

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

      Olá, estou usando o google tranlator para converter minha resposta aqui. Então, se estiver errado, podemos culpar o Google Translator aqui, lol.
      O que eu entendi pelo seu comentário é que você deseja obter a identificação do registro que você está tentando inserir? Isso está certo?

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

      ok, my written english is not very good so i will use google. I'm trying to update a table with a one-to-one relationship. Example:
      -user table
      -profile table
      how to update the user table at the same time update the profile table in EF.Core?
      I'm trying to do, example:
      user =
      {
      Id = 1,
      Name = "Joao",
      ProfileId = 1
      }
      profile =
      {
      Id = 1,
      Name = Administrator
      }
      user.profile = profile;
      database.usuario.Add (user);
      But now I need to update both tables at the same time.
      Without having to update one by one, Example:
      database.perfil.update (profile);
      database.user.update (user);

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

    Hi, I have an issue with saving cart. It saves cart but doesn't save product.cartId even though cart has id it shows null

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

      When you save Cart. EF core will return the cart_id that is getting auto incremented. You should assign that to product.cart_id before saving product. I hope I answered your question.

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

      @@CuriousDrive i solved the problem the issue was my add method. context.entry(entity)
      İ changed it to context.add(entity)

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

      @@CuriousDrive but why entry doesnt work 🤔?

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

    thank you for the videos, does evreything works on entityframework core 2.0 ?

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

      Honestly, I am not sure if all the things will work on core 2.0 or not.
      I would either upgrade to core 3.0 or just wait for .net 5

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

    That’s perfect!

    • @CuriousDrive
      @CuriousDrive  4 ปีที่แล้ว

      Thanks for watching Senka.

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

    Hi Curious Drive
    When i tried to save Related DataI am getting Error as
    "The INSERT statement conflicted with the FOREIGN KEY constraint".
    How you overcome this?

    • @CuriousDrive
      @CuriousDrive  4 ปีที่แล้ว

      Hello Vijay Kumar, it looks like you are trying insert record with either no foreign key or wrong foreign key. Let me know if you don't know what foreign keys are. I can direct you to some good resources

    • @mails4vijayakumar1
      @mails4vijayakumar1 4 ปีที่แล้ว

      @@CuriousDrive Hi Thanks for your reply.
      I did wrong Foreign Key mapping. Its working now..
      Thanks a lot

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

    thanks a lot bruh

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

    hi fahad.
    i have followed the method you teach with slight different based on json { "operator": "SearchPersonList", "info": { "DeviceID": 1379151, "Listnum": 1, "Totalnum": 3, "List": [ { "LibID": 8, "Name": "Mohd Rosdi"}]}}
    the db setup are :
    Class Operator ( one to one relationship) to class Info
    class list (one to many) to info
    however after creating the controller and posting the json from device or from postman causing the it save infinity relationship lopping to database.
    screencast-o-matic.com/watch/cY6lbG7V4A
    are there other way to map the json to the database and call it back with httpget?

    • @CuriousDrive
      @CuriousDrive  4 ปีที่แล้ว

      Hello Mohd, I am not sure why it is going into an infinite loop to create the response back.
      I don't recommend people to design their APIs this way. "SearchPersonList" should be a Web API method in the controller instead of a operator in the posting JSON. And for passing the filters, I usually create class called as "FilterDescriptor" which has the operators and the info. I hope this helps.

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

    Hi Fahad, You are just awesome. I liked your teaching method. Thaks for this detailed series.
    I am facing problem in Saving Related Data. I am using it in dotnet 6. Its showing me the following error :
    {
    "errors": {
    "Books[0].Pub": [
    "The Pub field is required."
    ],
    "Books[1].Pub": [
    "The Pub field is required."
    ],
    "Books[0].Sales[0].Book": [
    "The Book field is required."
    ],
    "Books[0].Sales[0].Store": [
    "The Store field is required."
    ],
    "Books[1].Sales[0].Book": [
    "The Book field is required."
    ],
    "Books[1].Sales[0].Store": [
    "The Store field is required."
    ]
    },
    "type": "tools.ietf.org/html/rfc7231#section-6.5.1",
    "title": "One or more validation errors occurred.",
    "status": 400,
    "traceId": "00-7efc87a57fb4eb3f1b0b34052b7cb492-2dfc23e4fb3bfd25-00"
    }

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

      I declared the navigation property type as a nullable reference type and all worked fine.
      Thanks for your kind effort. I am learning a lot from this series.