Because it contains a DefiningQuery and no UpdateFunction> element, the EntitySet cannot be updated.

.net asp.net c# entity-framework primary-key

Question

I'm using.net 3.5 with Entity Framework 1.

I'm just performing a basic thing like this:

var roomDetails = context.Rooms.ToList();

foreach (var room in roomDetails)
{        
   room.LastUpdated = DateTime.Now;
}

This error occurs whenever I attempt to:

 context.SaveChanges();

I experience a bug:

Unable to update the EntitySet - because it has a DefiningQuery and no <UpdateFunction> element exists in the <ModificationFunctionMapping> element to support the current operation.

Only when I attempt to edit this specific object am I seeing problems. I am updating the context often without any problems.

All of my searches come back with the same result: the object I'm attempting to change has no stated primary key. Unfortunately, I have a Primary key declared.

1
531
12/5/2019 12:07:00 PM

Accepted Answer

Usually, one of the following causes is at play:

  • Database view is used to map the Entity Set.
  • a specific Database search
  • A database table lacks a primary key.

In order to stop seeing the problem after doing this, you may still need to update in the Object Framework designer (or, alternatively, remove the entity and then add it).

1016
9/25/2016 3:30:54 PM

Popular Answer

Just give the table a main key. I'm done now. Issue is resolved.

ALTER TABLE <TABLE_NAME>
ADD CONSTRAINT <CONSTRAINT_NAME> PRIMARY KEY(<COLUMN_NAME>)


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow