Vote count:
0
my app is a movie collection manager. I created an EF model-first db. I've got a Person Entity with a Pictures property which is a collection of Picture Entity.
Given a movie title, I grab all informations from the web and get a list of actors (= Person entities). For each of them, I create a new List with a new Picture object that contains the picture grabbed from web.
For each Person, the only picture that's in the Pictures property has the same Id property (since they're all independant List). So when I try to update database, a DbUpdateException is thrown saying 'Multiple added entities may have the same primary key'.
Easily understandable, but I always thought EF would handle all this stuff by its own (that is putting each Picture from each Person.Pictures collection in the Picture table would give it a different Id).
That's not the case apparently. To handle this, I'd have to create directly a Picture In the Picture table, which then has no sense for me, according to my model: a picture is attached to a person so I create it when I create a Person object. If not, what's the benefit to use model-first way ?
Have I missed something to handle that ?
PS: see here a picture of my simplified model to illustrate how all the stuff is interconnected.
Same primary keys error when tempting to update Db
Aucun commentaire:
Enregistrer un commentaire