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

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

问题描述

这件事让我发疯了,而错误是毫无意义的对我说:

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

无法更新EntitySet的'表B',因为它有一个DefiningQuery并没有元素的元素存在,以支持当前的操作。

我的表放在这样的:


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

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

表B在SQL服务器没有定义主键。实体框架已进口的表和协会,并设置这两个领域为重点。但它会输出,当我尝试做一个插入到表错误!

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!

什么是错的?


编辑:
作为由Alex建议,解决的办法是这样的:

As suggested by Alex, the solution was this:


  1. 右键点击EDMX文件,选择打开方式,XML编辑器

  2. 找到在EDMX实体:StorageModels元素

  3. 删除DefiningQuery完全

  4. 重命名的店:模式=DBO来架构=DBO(否则,code会产生一个错误,说的名字是无效的)

  5. 删除店:Name属性

我离开的关键,因为它是,因为它是确定我,无论是列是关键的组成部分。

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

推荐答案

那么,当没有的PrimaryKey遇到表被视为一个视图。

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

和意见在EDMX文件显示在StorageModel \\ EntitySet的(在XML编辑器,看看开)[N] \\ DefiningQuery元素。

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

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

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.

但是,你有两种选择:

更改密钥definion:

Change the key definion:


  1. And说服EF什么它认为是一个视图确实是一个表

  2. 或者添加相应的修改功能

在你的情况我建议(1)。

In your case I recommend (1).

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

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