Oracle + Entity Framework 更新没有设置主键的表

时间:2023-02-15 08:23:05

最近用Entity Framework 开发的时候,发现一个问题,在默认情况下,EF不能对一个没有主键的表进行更新、插入和删除的动作。

那么,应该怎么处理没有主键的表呢?

我们打开这个表的edmx文件,可以看到以下的xml片段

<EntitySet Name="REP" EntityType="Model.Store.REP" store:Type="Tables" store:Schema="FOREST" store:Name="REP">
<DefiningQuery>SELECT
"REP"."ZONE" AS "ZONE",
"REP"."NO" AS "NO",
"REP"."HELP_NO" AS "HELP_NO",
"REP"."NO_TYPE" AS "NO_TYPE",
"REP"."ID_NO" AS "ID_NO",
"REP"."NAME" AS "NAME",
"REP"."TEL" AS "TEL",
"REP"."MAIL_NO" AS "MAIL_NO",
"REP"."ADDRESS1" AS "ADDRESS1",
"REP"."ADDRESS2" AS "ADDRESS2",
"REP"."JOINDATE" AS "JOINDATE",
"REP"."ELITE_D" AS "ELITE_D",
"REP"."PD1" AS "PD1",
"REP"."CUR_CPS" AS "CUR_CPS",
"REP"."PREV_CPS1" AS "PREV_CPS1",
"REP"."YEAR_CPS" AS "YEAR_CPS",
"REP"."IA_CPS" AS "IA_CPS",
"REP"."PREV_BAL" AS "PREV_BAL",
"REP"."CUR_BAL" AS "CUR_BAL",
"REP"."ELITE" AS "ELITE",
"REP"."CUR_CAMP" AS "CUR_CAMP",
"REP"."SALES" AS "SALES",
"REP"."RETURN" AS "RETURN",
"REP"."NO_ACT" AS "NO_ACT",
"REP"."PD_NO" AS "PD_NO",
"REP"."CUR_ORDER" AS "CUR_ORDER",
"REP"."BIRTHDAY" AS "BIRTHDAY",
"REP"."RNAM" AS "RNAM",
"REP"."POST_YN" AS "POST_YN",
"REP"."CARD_NO" AS "CARD_NO",
"REP"."CARD_YYYYMM" AS "CARD_YYYYMM",
"REP"."TEL2" AS "TEL2",
"REP"."MOBILE" AS "MOBILE",
"REP"."EMAIL" AS "EMAIL",
"REP"."PREV_CPS2" AS "PREV_CPS2",
"REP"."SEMAIL" AS "SEMAIL",
"REP"."PASSWORD" AS "PASSWORD",
"REP"."NEXT_CPS" AS "NEXT_CPS",
"REP"."TRAN_D" AS "TRAN_D",
"REP"."PASS_CNT" AS "PASS_CNT",
"REP"."ORDER_CT" AS "ORDER_CT",
"REP"."ORDER_AT" AS "ORDER_AT",
"REP"."SNAME" AS "SNAME",
"REP"."NOTES1" AS "NOTES1",
"REP"."NOTES2" AS "NOTES2",
"REP"."PPWD" AS "PPWD",
"REP"."SALES6" AS "SALES6",
"REP"."NO5" AS "NO5",
"REP"."SALES4" AS "SALES4",
"REP"."DELIVER" AS "DELIVER",
"REP"."ISWHWB" AS "ISWHWB",
"REP"."LOS" AS "LOS",
"REP"."CREDITLINE" AS "CREDITLINE",
"REP"."OCCUPATION" AS "OCCUPATION",
"REP"."ENTRYLOCATION" AS "ENTRYLOCATION",
"REP"."SOURCE" AS "SOURCE",
"REP"."SURVEYTAG" AS "SURVEYTAG",
"REP"."HMDATE" AS "HMDATE",
"REP"."ISRCVSMS" AS "ISRCVSMS",
"REP"."PAYMETHOD" AS "PAYMETHOD",
"REP"."ISPBAMCOURSE" AS "ISPBAMCOURSE",
"REP"."ISBSDCOURSE" AS "ISBSDCOURSE",
"REP"."BSADATE" AS "BSADATE",
"REP"."CUR_NETSALES" AS "CUR_NETSALES",
"REP"."WEBPCDATE" AS "WEBPCDATE",
"REP"."WEBPC" AS "WEBPC",
"REP"."ISMCNOTICE" AS "ISMCNOTICE",
"REP"."OLDNO" AS "OLDNO",
"REP"."EMAILACCOUNT" AS "EMAILACCOUNT",
"REP"."MCDATE" AS "MCDATE",
"REP"."PASS_CRTDATE" AS "PASS_CRTDATE",
"REP"."STARXNO" AS "STARXNO",
"REP"."ZONEID" AS "ZONEID",
"REP"."ORDER_INFO" AS "ORDER_INFO",
"REP"."TRAN_D_EC_DATE" AS "TRAN_D_EC_DATE",
"REP"."REALTITLEID" AS "REALTITLEID",
"REP"."PAIDTITLEID" AS "PAIDTITLEID",
"REP"."PUBLICTITLEID" AS "PUBLICTITLEID",
"REP"."ISASLF" AS "ISASLF",
"REP"."ASLFROSTARTCAMP" AS "ASLFROSTARTCAMP",
"REP"."ASLFROENDCAMP" AS "ASLFROENDCAMP",
"REP"."ISVIRTUALID" AS "ISVIRTUALID",
"REP"."ASLFSPONSORID" AS "ASLFSPONSORID",
"REP"."MPCACTCPS" AS "MPCACTCPS",
"REP"."MPCORDVAL" AS "MPCORDVAL",
"REP"."ASLFCDBENDCAMP" AS "ASLFCDBENDCAMP",
"REP"."ASLFSTARTCAMP" AS "ASLFSTARTCAMP",
"REP"."ISDRCERT" AS "ISDRCERT",
"REP"."DRCERTSTARTCAMP" AS "DRCERTSTARTCAMP",
"REP"."DRCERTENDCAMP" AS "DRCERTENDCAMP",
"REP"."DRFOUSECAMP" AS "DRFOUSECAMP",
"REP"."MAIL_NO1" AS "MAIL_NO1",
"REP"."ADDRESS12" AS "ADDRESS12",
"REP"."ADDRESS22" AS "ADDRESS22",
"REP"."RECOMMENDERID" AS "RECOMMENDERID",
"REP"."RECOMMENDERNAME" AS "RECOMMENDERNAME",
"REP"."RECOMMENDERNATIONALID" AS "RECOMMENDERNATIONALID",
"REP"."COAPPLICANTNAME" AS "COAPPLICANTNAME",
"REP"."COMPANYNAME" AS "COMPANYNAME",
"REP"."ISEINVOICE" AS "ISEINVOICE",
"REP"."ISDONATE_INVOICE" AS "ISDONATE_INVOICE",
"REP"."DRM_CREATEDDATE" AS "DRM_CREATEDDATE"
FROM "FOREST"."REP" "REP"</DefiningQuery>
</EntitySet>

我再加入一个有主键的表进行对比,可以看到有主键的表的定义如下。

<EntitySet Name="City" EntityType="Model.Store.City" store:Type="Tables" Schema="FOREST" />

我们把没有主键的<EntitySet>照着上面这个节点进行更改:删除<DefiningQuery>节点,将store:Schema=”FOREST”更改为Schema=”FOREST”。这样我们就可以对之前没有设置主键的表进行更新、删除以及插入操作了。

无主键的表SSDL定义其实更像是视图,我有一点不明的是store:这个命名空间的作用是什么,为什么只是删除<DefiningQuery>不行,还需要将Schema属性的store命名空间删除才可以。以上都是我还不明白的地方,只是作为一个解决方案,它确实简单可行。

Oracle + Entity Framework 更新没有设置主键的表的更多相关文章

  1. Entity Framework 无法对没有主键的视图映射实体的解决办法

    我们在使用Entity Framework的时候经常会把数据库中的某一个视图映射为EF的实体,但是如果数据库视图中的列没有包含表的主键列,EF会报出警告说视图没有主键,导致视图映射为实体失败,错误如下 ...

  2. Entity Framework 插入数据 解决主键非自增问题

    http://blog.csdn.net/educast/article/details/8632806 与Entity Framework相伴的日子痛并快乐着.今天和大家分享一下一个快乐,两个痛苦. ...

  3. Entity Framework Code First 遭遇主键自动生成问题

    4.0后就没有去跟踪后面的版本了.现在直接开始用5.0没想到在做User的GURD时就遭遇insert不进数据问题. ISet<User>.Add(user);_context.SaveC ...

  4. php&plus;mysql 除了设置主键防止表单提交内容重复外的另一种方法

    感觉好久没有更新博客了,一直在做网站及后台,也没有遇到让我觉得可以整理的内容,之前做的一个系统,已经完成了,后来客户又要求加一个功能,大概就是表单提交的时候,约束有一项不能和以前的内容重复,如图 比如 ...

  5. 关于oracle设置主键自增的问题

    关于orcale设置主键自增的问题 关于主键Oracle中并没有提供一个直接的语句设置,对于这个oralce一般都是用序列和触发器来实现 一下又两种方法来实现 一 ,不使用触发器 创建序列: crea ...

  6. oracle中如何设置主键并且让其自动增长

    由于oracle中是没有自动增长的的,需要自己去进行写触发器等方式去进行设置: 找了一下他人写的,有两种方法可以设置主键,一种是自增长主键,另一种就是生成唯一序列. 一.自增长主键 我创建一个用户的信 ...

  7. Oracle 设置主键自增长&lowbar;&lowbar;Oracle

    转自:https://yq.aliyun.com/ziliao/258074 如果想在Oracle数据库里实现数据表主键自增,我们似乎没有办法像MySql般直接定义列的属性来实现.不过对于这个数据库的 ...

  8. 在Oracle中设置主键自增

    转自:https://www.2cto.com/database/201705/636725.html 数据库设置主键自增">oracle数据库设置主键自增: --创建表 create ...

  9. Oracle 设置主键自增长

    如果想在Oracle数据库里实现数据表主键自增,我们似乎没有办法像MySql般直接定义列的属性来实现.不过对于这个数据库的常用功能,我们还是有办法实现的.这里将展示使用触发器来实现主键自增. 1.准备 ...

随机推荐

  1. git 教程(8)--删除文件

    在Git中,删除也是一个修改操作,我们实战一下,先添加一个新文件test.txt到Git并且提交:

  2. Codeforces Beta Round &num;93 &lpar;Div&period; 1 Only&rpar; D&period; Fibonacci Sums

    先考虑一个斐波那契数能分成其他斐波那契数的方案,假如f[i]表示第i个斐波那契数,那么只要对他进行拆分,f[i-1]这个数字必定会存在.知道这一点就可以进行递推了.先将数字分成最少项的斐波那契数之和, ...

  3. hibernate建表多对多建表

    Student.java package cn.itcast.hiberate.sh.domain; import java.util.Set; public class Student { priv ...

  4. C&plus;&plus;重要知识点小结---2

    C++重要知识点小结--1 :http://www.cnblogs.com/heyonggang/p/3246631.html 1.C++允许程序员声明一个不能有实例对象的类,这样的类惟一的用途是被继 ...

  5. 使用ServiceStackRedis链接Redis简介 &lbrack;转&rsqb;

      注:关于如何在windows,linux下配置redis,详见这篇文章:)          Discuz!NT中的Redis架构设计 目前网上有一些链接Redis的C#客户端工具,这里介绍其中也 ...

  6. HDU 4638 Group &starf;&lpar;树状数组&rpar;

    题意 询问一段区间里的数能组成多少段连续的数. 思路 先考虑从左往右一个数一个数添加,考虑当前添加了i - 1个数的答案是x,那么可以看出添加完i个数后的答案是根据a[i]-1和a[i]+1是否已经添 ...

  7. 这样就算会了PHP么?-11

    PHP中关于类的基本内容练习: <?php class SportObject{ public $name; public $height; public $avirdupois; public ...

  8. 案例研究:Web应用出现间歇性的SqlException

    案例研究:Web应用出现间歇性的SqlException 2013-07-29 14:36 by 微软互联网开发支持, 231 阅读, 3 评论, 收藏, 编辑 最近有客户找到我,说他们生产环境的事件 ...

  9. synchronized细节问题&lpar;一&rpar;

    synchronized锁重入: 关键字synchronized拥有锁重入的功能,也就是在使用synchronized时,当一个线程得到一个对象的锁后,再次请求此对象时是可以再次得到该对象的锁. 下面 ...

  10. linux命令学习之:route

    我们在网络基础的时候谈过关于路由的问题,两台主机之间一定要有路由才能够互通TCP/IP的协议,否则就无法进行联机.一般来说,只要有网络接口,该接口就会产生一个路由,例如:eth0及lo. route命 ...