It has a DefiningQuery but no InsertFunction element… err

后端 未结 6 1964
猫巷女王i
猫巷女王i 2020-11-28 20:56

This thing is driving me crazy, and the error is quite meaningless to me:

Unable to update the EntitySet \'TableB\' because it has a DefiningQuery and no elemen

相关标签:
6条回答
  • 2020-11-28 20:59

    Just Add a primary key to the table. That's it. Problem solved.

    ALTER TABLE <TABLE_NAME>
    ADD CONSTRAINT <CONSTRAINT_NAME> PRIMARY KEY(<COLUMN_NAME>)
    
    0 讨论(0)
  • 2020-11-28 20:59

    I was missing a primary key on my table and got this error message. One thing I noted was after I added the key to the table, I needed to clear the table from the edmx using the designer, save the edmx, then update it again to add the table back in. It wasn't picking up the key since it was already assigned as a view. This didn't require editing the edmx manually.

    0 讨论(0)
  • 2020-11-28 21:15
    1. You need to manually open the .EDMX file in notepad or notepad++ or in any text editor of your choice.
    2. Locate the entry in edmx:StorageModels in file opened in step1.
    3. Find the DefiningQuery element and remove this tag entirely.
    4. Find the store:Schema="dbo" to Schema="dbo" (if you skip this step it will generate error of the name is invalid).
    5. Save and close the file.

    Hope it will solve the problem.

    0 讨论(0)
  • 2020-11-28 21:17

    Add primary key to table, delete the model from the edmx model, then select update from database, build and run...... works

    0 讨论(0)
  • 2020-11-28 21:18

    Well when a table is encountered without a PrimaryKey it is treated as a View.

    And views show up in the EDMX file (open in an XML editor to see) in the StorageModel\EntitySet[n]\DefiningQuery element.

    When you have a DefiningQuery the Entity becomes readonly unless you add modification functions. You need 3 modifications functions (aka Stored Procedures) one for each of Insert, Update and Delete.

    But you have two options:

    Change the key definion:

    1. And convince the EF that what it thinks is a view is really a table
    2. Or add the appropriate modification functions

    In your case I recommend (1).

    0 讨论(0)
  • 2020-11-28 21:22

    @Palantir. Verify that both of you tables have Primary Keys set, and be careful with multiple primary keys set in a table.

    0 讨论(0)
提交回复
热议问题