Entity Framework 4 Error: Unable to update the EntitySet because it has a DefiningQuery

前端 未结 4 1352
臣服心动
臣服心动 2021-01-01 19:23

Okay, here\'s the scenario. I have 3 tables. One called aspnet_Users one called Categories and a linking table called User_Categories. aspnet_Users and Categories both ha

相关标签:
4条回答
  • 2021-01-01 20:02

    Put a composite primary key on the mapping table, this will tell EF to handle it correctly.

    0 讨论(0)
  • 2021-01-01 20:14

    I assume the full exception message is something similar to:

    Unable to update the EntitySet YourTableName because it has a DefiningQuery and no InsertFunction element exists in the ModificationFunctionMapping element to support the current operation.

    This will occur if your DB's table doesn't have a primary key defined.

    Add a primary key to your table (using SQL Server Management Studio or whatever), and update your .edmx model from the database.

    0 讨论(0)
  • 2021-01-01 20:15

    I encounter the same problem, and I fixed by the following link:

    • Link @ Microsoft social forum
    • Link @ StackOverflow
    • Link @ Blog of Microsoft

    I remove the section of DefiningQuery in .edmx based on the content of 3rd link. And then everything works as a charm.

    0 讨论(0)
  • 2021-01-01 20:19

    Error: Unable to update the EntitySet because it has a DefiningQuery

    Twice I got this error, twice I searched for answers everywhere, and in the end my mappings was messed up or the database had no primary key or something. I suggest checking it all out...

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