It has a DefiningQuery element but no InsertFunction... err entity-framework


The mistake is completely meaningless to me, and this item is driving me crazy:

EntitySet "TableB" cannot be updated because it includes a DefiningQuery and the element lacks the necessary elements to support the requested action.

My tables are set up as follows:

int idA (identity, primary key)

int idA (FK for TableA.idA)
int val

The SQL server does not have a primary key specified for TableB. The table and association were imported into the Entity Framework, and both fields were designated as keys. But if I attempt to insert data into the table, it will print that error!

What's the issue?

Edit: The answer, as Alex had indicated, was this:

  1. Open the edmx file using an XML editor by doing a right click on it.
  2. Find the entity in the storage models element of the edmx file.
  3. Eliminate the DefiningQuery completely.
  4. The store:Schema="dbo" should now read Schema="dbo" (otherwise, the code will generate an error saying the name is invalid)
  5. Delete the property store:Name

Since I thought it was OK that both columns were included in the key, I left it exactly as it was.

10/20/2009 7:11:50 AM

Accepted Answer

In any case, a table without a PrimaryKey is handled as a view.

Additionally, views may be found in the StorageModelEntitySet[n]DefiningQuery element of the EDMX file (open it in an XML editor to check).

The Entity becomes read-only when you have a DefiningQuery until you provide modification functions. Each of the three changes functions (also known as stored procedures), one for insert, update, and delete, is required.

However, you have two choices:

Modify the key definition:

  1. Additionally, persuade the EF that what it perceives as a view is really a table.
  2. or provide the necessary modification features

In your situation, I advise (1).

1/17/2012 7:24:31 PM

Popular Answer

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


Related Questions


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