I have a property that contains a list from an entity in my model. I want to add an item to this list but when I do, it's added as detached. How can I add this object as attached?
using (var db = new fsEntities())
{
var list = db.Products.Where(x => x.ID == 1).ToList();
var p = new Product { Description = "New Item", Amount = 14};
list.Add(p); //the new item EntityState is detached
}
I know I can do this, db.AddToProducts(p), but in my scenario I want to add the object to the existing property with it's EntityState as attached, then later perform a SaveChanges if necessary.
How can I do this?
Detachedstate by default. Only in Insert method that generates for you EntityState changed toAdded.