I have Book and Author objects with many relationships, and I'm trying to save the relationship (entry in the connection table) using the first approach to the database.
I would like to start with my working version of the code
[HttpPost] public ActionResult Edit(BookViewModel bookv) { Mapper.CreateMap<AuthorViewModel, Author>(); List<Author> authors = Mapper.Map<List<AuthorViewModel>, List<Author>> (bookv.Authors.ToList());
In the above code, I retrieve the Author object (record) from the database to add a relation to the book object. While I do not take the Book object from the database, but bind it to the context. Can't I do something similar with Author objects?
I tried to do this with this code, but first adds new entries to the Author table and adds relevance to books and newly created (unwanted) authors:
[HttpPost] public ActionResult Edit(BookViewModel bookv) { Mapper.CreateMap<AuthorViewModel, Author>(); List<Author> authors = Mapper.Map<List<AuthorViewModel>, List<Author>>(bookv.Authors.ToList());
asp.net-mvc asp.net-mvc-3 entity-framework many-to-many entity-framework-4
Bishnu Paudel Jul 06 2018-12-12T00: 00Z
source share