The property is part of the object's key information and cannot be modified

asp.net-mvc c# entity-framework entity-framework-6

Popular Answer

I assume you attempt to update primary keys after reading records from the EF Context using the List networkinfo function argument. EF keeps note of any changes as you read them and will update them on SaveChages (despite you called Add method implying to insert). So, the query to the database might look like this:

UPDATE NetworkInfo
SET NETWORKID = 5
WHERE NETWORKID = 1

However, EF does not permit changing the main key, therefore the following is likely the cause:

it might be that is can't/doesn't want to handle cascading the update to all FKs

As a result, the first case has an exception.
In the second scenario, EF receives a new object, and the database server receives a typical insert.

1
5/23/2017 12:21:43 PM


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