Oracle + Entity Framework 更新没有设置主键的表
最近用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 更新没有设置主键的表的更多相关文章
- Entity Framework 无法对没有主键的视图映射实体的解决办法
我们在使用Entity Framework的时候经常会把数据库中的某一个视图映射为EF的实体,但是如果数据库视图中的列没有包含表的主键列,EF会报出警告说视图没有主键,导致视图映射为实体失败,错误如下 ...
- Entity Framework 插入数据 解决主键非自增问题
http://blog.csdn.net/educast/article/details/8632806 与Entity Framework相伴的日子痛并快乐着.今天和大家分享一下一个快乐,两个痛苦. ...
- Entity Framework Code First 遭遇主键自动生成问题
4.0后就没有去跟踪后面的版本了.现在直接开始用5.0没想到在做User的GURD时就遭遇insert不进数据问题. ISet<User>.Add(user);_context.SaveC ...
- php+mysql 除了设置主键防止表单提交内容重复外的另一种方法
感觉好久没有更新博客了,一直在做网站及后台,也没有遇到让我觉得可以整理的内容,之前做的一个系统,已经完成了,后来客户又要求加一个功能,大概就是表单提交的时候,约束有一项不能和以前的内容重复,如图 比如 ...
- 关于oracle设置主键自增的问题
关于orcale设置主键自增的问题 关于主键Oracle中并没有提供一个直接的语句设置,对于这个oralce一般都是用序列和触发器来实现 一下又两种方法来实现 一 ,不使用触发器 创建序列: crea ...
- oracle中如何设置主键并且让其自动增长
由于oracle中是没有自动增长的的,需要自己去进行写触发器等方式去进行设置: 找了一下他人写的,有两种方法可以设置主键,一种是自增长主键,另一种就是生成唯一序列. 一.自增长主键 我创建一个用户的信 ...
- Oracle 设置主键自增长__Oracle
转自:https://yq.aliyun.com/ziliao/258074 如果想在Oracle数据库里实现数据表主键自增,我们似乎没有办法像MySql般直接定义列的属性来实现.不过对于这个数据库的 ...
- 在Oracle中设置主键自增
转自:https://www.2cto.com/database/201705/636725.html 数据库设置主键自增">oracle数据库设置主键自增: --创建表 create ...
- Oracle 设置主键自增长
如果想在Oracle数据库里实现数据表主键自增,我们似乎没有办法像MySql般直接定义列的属性来实现.不过对于这个数据库的常用功能,我们还是有办法实现的.这里将展示使用触发器来实现主键自增. 1.准备 ...
随机推荐
- Ribbon 窗体的 MDI 子窗体使用 TabbedMDIManager 切换时工具条闪屏问题的解决办法
补充说明: 此问题已经在新版本中解决(15.2.6),方法更加简单,只需要在 MDIChild 窗体的 Create 方法中,将 Ribbon 的 Visible 属性设置为 false 就可以了,且 ...
- mac 环境下mysql 不能删除schema问题的解决办法
首先说明下问题环境,我是在mac机器上安装的mysql+workbench. 在删除一个数据库的时候,出现error dropping database cant rmdir ./test 的问题. ...
- [Redux + Webpack] Hot reloading Redux Reducers with Webpack
Webpack will hot reload the component, but the reducer we need hard refresh. To sovle the problem, g ...
- C#多线程的介绍(园子里比较全的一篇)
一.多线程的概念 Windows是一个多任务的系统,如果你使用的是windows 2000及其以上版本,你可以通过任务管理器查看当前系统运行的程序和进程.什么是进程呢?当一个程序开始运行时,它就是一 ...
- TortoiseGit安装和使用的图文教程
ortoiseGit是Windows下不错的一款Git客户端工具,在Mac下推荐使用sourcetree.下面就介绍一下TortoiseGit安装和使用的方法. 安装TortoiseGit并使用它需要 ...
- 《Java程序员面试宝典》读书笔记1
今天读书发现一个很有趣的问题 请问以下程序会输出什么? public class Test2 { public static void main(String[] arg ...
- vim中taglist使用
转载:http://www.cnblogs.com/mo-beifeng/archive/2011/11/22/2259356.html 本节所用命令的帮助入口: :help helptags :he ...
- centos 配置NFS服务器
转载:http://boloveyo.blog.163.com/blog/static/203926187201232383956558/ 系统是CentOS5.6,假设NFS Server IP为1 ...
- i = i++;
在这里jvm里面有两个存储区,一个是暂存区(是一个堆栈,以下称为堆栈),另一个是变量区.语句istore_1是将堆栈中的值弹出存入相应的变量区(赋值):语句iload_1是将变量区中的值暂存如堆栈中. ...
- 小白日记27:kali渗透测试之Web渗透-Http协议基础,WEB
Http协议基础 Web技术发展[http://www.cnblogs.com/ProgrammerGE/articles/1824657.html] 静态WEB[网页] 动态WEB 属于一种应用程序 ...