I\'ve been using Database First, EF 4.1
I am getting \"The entity type List`1 is not part of the model for the current context.\" error when trying to update a recor
Thanks, Leniency, for the answer. Worked great.
For what it's worth, I prefer to keep my EntityState.Modified
assignments on a single line (as I have multiples) so used the following LINQ:
properties.ForEach(p => db.Entry(p).State = EntityState.Modified);
i think you can use this code for this problem. Because if you use it, you will met another problem. Now i fixed my problem and i hope it will work for you
foreach (var item in properties)
{
var oldEntity = FGetById(item.Id); // You can use find instead of FGetById
context.Entry(oldEntity).CurrentValues.SetValues(item);
Update(oldEntity);
}
Try changing your loop to:
foreach (var item in properties)
{
db.Entry(item).State = EntityState.Modified;
}
You were calling db.Entry(properties)
, so you were trying to attach the whole collection at once. DbContext.Entry(object) expects a single object, not a collection.
I ended up here despite using code-first EF. The answer to the problem for me was simply not to try to pass a list of entities to the insert method, but insert them one at a time instead:
entityList.ForEach(context.Insert);