它有一个DefiningQuery但没有InsertFunction元素...错误 [英] It has a DefiningQuery but no InsertFunction element... err

查看:103
本文介绍了它有一个DefiningQuery但没有InsertFunction元素...错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个东西让我疯狂,错误对我来说毫无意义:



无法更新EntitySet'TableB',因为它有一个DefiningQuery并且元素中没有元素支持当前操作。



我的表格如下所示:

 
TableA
int idA(身份,主键)
...

TableB
int idA(FK for TableA .idA)
int val

TableB在SQL服务器中没有定义的主键。实体框架导入了表和关联,并将这两个字段设置为关键字。但是当我尝试插入表格时会输出错误!



发生什么问题?






编辑:
按照Alex的建议,解决方案是:


  1. 右键单击edmx文件,选择Open with,XML editor

  2. 在edmx:StorageModels元素中找到该实体

  3. 完全删除DefiningQuery

  4. 将商店重命名为:Schema =dbo到Schema =dbo(否则代码将生成一个错误,名称无效)

  5. 删除商店:名称属性

我离开了钥匙,因为它是可以的这两列都是键的一部分。

解决方案

当没有PrimaryKey的表遇到时,它被视为视图



在StorageModel\EntitySet [n] \DefiningQuery元素中,EDMX文件(在XML编辑器中打开)可以看到。 >

当您有一个DefiningQuery时,实体变为只读,除非您添加修改功能。每个插入,更新和删除都需要3个修改功能(又称存储过程)。



但是你有两个选择:



更改密钥定义:


  1. 并且说服EF,它认为是一个视图真的是一个表

  2. 或添加适当的修改功能

在您的情况下,我推荐(1)。


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 element exists in the element to support the current operation.

My tables are put like this:

TableA
int idA (identity, primary key)
...

TableB
int idA (FK for TableA.idA)
int val

TableB has no defined primary key in the SQL server. The Entity Framework has imported the table and the association and set both fields as key. But it will output that error when I try to do an insert into the table!

What's wrong??


Edit: As suggested by Alex, the solution was this:

  1. Right click on the edmx file, select Open with, XML editor
  2. Locate the entity in the edmx:StorageModels element
  3. Remove the DefiningQuery entirely
  4. Rename the store:Schema="dbo" to Schema="dbo" (otherwise, the code will generate an error saying the name is invalid)
  5. Remove the store:Name property

I left the key as it was, since it was OK to me that both the columns are part of the key.

解决方案

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).

这篇关于它有一个DefiningQuery但没有InsertFunction元素...错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆