I have a foreach loop that iterates through a list of type List<NewItem>, creates a new instance of NewItem, sets its properties, then Add()s the item to the context to be inserted upon the execution of SaveChanges():
foreach (var newItem in newItems)
{
NewItem item = new NewItem
{
User = newItem.User,
Itemno = newItem.Itemno
};
db.NewItem.Add(item);
}
try
{
db.SaveChanges();
}
catch (Exception e)
{
Console.WriteLine(e);
}
I am getting the error:
Unable to update the EntitySet 'NewItem' because it has a DefiningQuery and no element exists in the element to support the current operation.
Why isn't the Add() method actually adding anything to my db context?