New to Linq to Entities. I am using entity framework and linq. In my db I have something akin to Cars, Users, UserCars where UserCars holds the ID from User and Cars. Standard stuff.
EF maps this to Car and User objects.
Now a user currently has many cars. Through my application I end up with a new List of Car IDs.
I need to update the UserCars table with the new list of cars for the current user.
So what needs to happen basically, The current cars for the user are deleted, and the new list of car ids/userid is inserted.
What is the easiest way to go about this using linq to entities?
The
Userentity should have aCarsproperty. You can just clear that collection and then add the new Cars to reflect the new state, i.e. somewhat like this: