Entity Framework Add()to ORACLE DB引发不允许在虚拟列上执行的INSERT操作[已关闭]

btxsgosb  于 2023-08-04  发布在  Oracle
关注(0)|答案(1)|浏览(87)

**已关闭。**此问题需要debugging details。它目前不接受回答。

编辑问题以包括desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将有助于其他人回答这个问题。
24天前关闭
Improve this question
我有Oracle数据库,它有多个表(其中三个表的ID列总是生成标识),需要连接到Windows窗体。
分解表

CREATE TABLE "BREAKDOWN" 
   ("EQUIPMENTID" NCHAR(8) NOT NULL ENABLE, 
    "FROMTIME" TIMESTAMP (4), 
    "TOTIME" TIMESTAMP (4), 
    "WORKORDER" NUMBER(10,0) NOT NULL ENABLE, 
    "BDNREASON" NCHAR(10), 
    "BDNTIME" INTERVAL DAY (2) TO SECOND (6) GENERATED ALWAYS AS (("TOTIME"-"FROMTIME")DAY(9) TO SECOND(4)) VIRTUAL , 
    "BREAKDOWNID" NUMBER(10,0) GENERATED ALWAYS AS IDENTITY MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER  NOCYCLE  NOT NULL ENABLE, 
     CONSTRAINT "BREAKDOWN_PK" PRIMARY KEY ("BREAKDOWNID") )

字符串
BREAKDOWN生成的类

public partial class BREAKDOWN
    {
        public string EQUIPMENTID { get; set; }
        public Nullable<System.DateTime> FROMTIME { get; set; }
        public Nullable<System.DateTime> TOTIME { get; set; }
        public int WORKORDER { get; set; }
        public string BDNREASON { get; set; }
        public int BREAKDOWNID { get; set; }
        public Nullable<decimal> BDNTIME { get; set; }
    
        public virtual EQUIPMENT EQUIPMENT { get; set; }
        public virtual WORKORDER WORKORDER1 { get; set; }
    }


WORKORDER表

CREATE TABLE "WORKORDER" 

       (
        "WORKORDERTYPEID" NCHAR(3) NOT NULL ENABLE, 
        "WORKORDEREQUIPMENTID" NCHAR(8) NOT NULL ENABLE, 
        "WORKORDERREGISTERATIONDATE" TIMESTAMP (3) NOT NULL ENABLE, 
        "WORKORDERID" NUMBER(10,0) GENERATED ALWAYS AS IDENTITY MINVALUE 1 MAXVALUE 9999999999999999999999999999 INCREMENT BY 1 START WITH 1 NOCACHE  NOORDER  NOCYCLE  NOT NULL ENABLE, 
         CONSTRAINT "WORKORDER_PK" PRIMARY KEY ("WORKORDERID")
    )


WORKORDER生成的类

public partial class WORKORDER
    {
        public WORKORDER()
        {
            this.BREAKDOWNs = new HashSet<BREAKDOWN>();
        }
        public string WORKORDERTYPEID { get; set; }
        public string WORKORDEREQUIPMENTID { get; set; }
        public System.DateTime WORKORDERREGISTERATIONDATE { get; set; }
        public int WORKORDERID { get; set; }
    }


如果我尝试使用ORACLE SQL Developer进行INSERT,则IDENTITY对这三个表可以正常工作
whileas如果我尝试使用Windows窗体视图使用(Add()Function)插入,则会引发上述错误:
System.Data.Entity.Infrastructure.DbUpdateException:'更新条目时出错。有关详细信息,请参见内部异常。更新条目时出错。有关详细信息,请参见内部异常。OracleException:ORA-54013:不允许对虚拟列执行INSERT操作ORA-06512:在4号线
仅在BREAKDOWN时出现此情况

BREAKDOWN newBDN = new BREAKDOWN();
newBDN.WORKORDER = workOrder.WORKORDERID;
newBDN.EQUIPMENTID = workOrder.WORKORDEREQUIPMENTID;
newBDN.FROMTIME = bdnFromDateTimePicker.Value;
home.dbContext.BREAKDOWNs.Add(newBDN);
home.dbContext.SaveChanges();


WORKORDER表运行正常!!

WORKORDER newWorkOrder= new WORKORDER ();
newWorkOrder.EQUIPMENT = (EQUIPMENT) equipmentBindingSource.DataSource;
newWorkOrder.WORKORDERREGISTERATIONDATE = regsiterationDatePicker.Value;
newWorkOrder.WORKORDERTYPE = (WORKORDERTYPE)workTypeTextBox.SelectedItem;
home.dbContext.WORKORDERs.Add(newWorkOrder);
home.dbContext.SaveChanges();


我已保证:

  • 列均为具有所需ISEQ的IDENTITY。
  • 所有列的数据类型在DBTables和Entity中是相同的。
  • ORACLE正在正确计算IDENTITY属性(使用ORACLE SQL Developer手动插入)
bttbmeg0

bttbmeg01#

我认为这不是 identity 列,而是另一个- virtual列。例如,类似这样的东西:见第7行,哪一行是虚拟列?

SQL> CREATE TABLE test_so
  2  (
  3     id           NUMBER GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  4     name         VARCHAR2 (10),
  5     salary       NUMBER,
  6     commission   NUMBER,
  7     total        NUMBER GENERATED ALWAYS AS (salary + commission) VIRTUAL
  8  );

Table created.

字符串
如果我尝试在其中插入值,Oracle会引发错误(与您得到的相同):

SQL> insert into test_so (name, salary, commission, total)
  2    values ('Little', 100, 20, 120);
insert into test_so (name, salary, commission, total)
                                               *
ERROR at line 1:
ORA-54013: INSERT operation disallowed on virtual columns


如果省略total

SQL> insert into test_so (name, salary, commission)
  2    values ('Little', 100, 20);

1 row created.

SQL> select * from test_so;

        ID NAME           SALARY COMMISSION      TOTAL
---------- ---------- ---------- ---------- ----------
         1 Little            100         20        120

1 row selected.

SQL>


因此,检查这些表中是否有任何虚列。怎么做?像这样:

SQL> SELECT column_name, data_default
  2    FROM user_tab_columns
  3   WHERE table_name = 'TEST_SO';

COLUMN_NAME     DATA_DEFAULT
--------------- ----------------------------------------
ID              "SCOTT"."ISEQ$$_258989".nextval
NAME
SALARY
COMMISSION
TOTAL           "SALARY"+"COMMISSION"

5 rows selected.

SQL>

相关问题