0

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?

1 Answer 1

1

If the target database table doesn't have a primary key, add one.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.