I have a Model that looks like this:public class Item{    public Item()    {        FilePaths = new List<ItemFilePath>();    }    public int Id { get; set; }    public virtual ICollection<ItemFilePath> FilePaths { get; set; }}public class ItemFilePath{    public int Id { get; set; }    public virtual Item Item { get; set; }}I have generated Post and Put methods in Web API 2 from this Model. The Post works as intended, however the Put method have given me a lot of trouble. The standard Put method basically just does this:public IHttpActionResult PutItem(int id, Item item){    db.Entry(item).State = EntityState.Modified;}This saves the Item object, but any added or deleted FilePaths are not saved. Therefore by following this and this I came up with a solution that looks almost identical to that answer:public IHttpActionResult Put(int id, Item item){    var oldItem = db.Items.Find(item.Id);         db.Entry(oldItem).Collection(b => b.FilePaths).Load();    var deletedFilePaths = oldItem.FilePaths.ExceptBy(item.FilePaths, x => x.FilePath).ToList();    foreach (var filePath in deletedFilePaths)    {        oldItem.FilePaths.Remove(filePath);        db.ItemFilePaths.Remove(filePath);    }    var addedFilePaths = item.FilePaths.ExceptBy(oldItem.FilePaths, x => x.FilePath).ToList();    foreach (var filePath in addedFilePaths)    {        oldItem.FilePaths.Add(filePath);    }    var itemEntry = db.Entry(oldItem);    itemEntry.CurrentValues.SetValues(item);    db.SaveChanges();}This is working as intended. However I can't shake the feeling that this is overly complex for something I would expect EF to be able to do automatically. I mean this is a very simple One-To-Many relationship, and I expect we will soon be facing Objects that have more Virtual Properties, and those themselves have Virtual Properties and what then?So my question is, is this really the best way to go about updating Virtual Properties? Or am I missing something obvious or is there something wrong with my assumption that EF should be able to handle this automatically?
Update Virtual Property in a Code First Model using Independent Association in Entity Framework 6
c#;.net;entity framework