如何使用LINQ从没有主键的表中插入/更新/删除记录 [英] How to insert/update/delete records from tables without primary key using LINQ

查看:44
本文介绍了如何使用LINQ从没有主键的表中插入/更新/删除记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用LINQ连接到第三方数据库.

I'm using LINQ to connect to a third party database.

现在,我必须将一些记录插入没有主键集的表中,并且出现此异常:

Now I have to insert some records into a table that have no primary key set and I get this exception:

System.InvalidOperationException:无法对表(the_table)"执行创建,更新或删除操作,因为它没有主键.

我该如何解决?我应该使用 ExecuteCommand 来避免此异常吗?

How can I solve this? should I use ExecuteCommand to avoid this exception?

推荐答案

将唯一列用作EF模型中的PK.

use the unique column as a PK in the EF model.

这篇关于如何使用LINQ从没有主键的表中插入/更新/删除记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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