JonPSmith / EfCore.GenericServices

A library to help you quickly code CRUD accesses for a web/mobile/desktop application using EF Core.
https://www.thereformedprogrammer.net/genericservices-a-library-to-provide-crud-front-end-services-from-a-ef-core-database/
MIT License
601 stars 94 forks source link

How to replace a row in many to many relationship using generic services? #51

Closed nishojib closed 4 years ago

nishojib commented 4 years ago

How would you go about replacing a row in many to many relationship using generic services? The current behavior allows me to add a new row whenever I am trying to change it using a DTO.

I want a behavior similar to the test TestChangeAuthorsNewListOk in Ch03_ManyToManyUpdate of your book using generic services.

Thank you.

JonPSmith commented 4 years ago

Hi @supremeboy18,

Firstly, the test TestChangeAuthorsNewListOk in Ch03_ManyToManyUpdate ADDS a new BookAuthor many-to-many linking class to a Book entity class, which adds another Author to the many-to-many relationships. If that is what you need then you could use CreateAndSave<T> method with a BookAuthor entity class or a DTO that mapped to the BookAuthor entity class.

If you really want to update an existing BookAuthor many-to-many linking class, then you can't use GenericServices and have to do it by hand. That's because GenericServices can't change a primary key.

I hope that helps.