0

I have Oracle DB that has multiple Tables (Three of them have ID Column with ALWAYS GENERATED IDENTITY) that is required to be connected to Windows Form.

BREAKDOWN Table

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 Generated Class

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 Table

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 Generated Class

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; }
    }

IDENTITY is working properly for the three tables if I tried to INSERT using ORACLE SQL Developer

whileas if I tried to insert using the Windows form View using (Add() Function) it raises the mentioned Error:

System.Data.Entity.Infrastructure.DbUpdateException: 'An error occurred while updating the entries. See the inner exception for details.' UpdateException: An error occurred while updating the entries. See the inner exception for details. OracleException: ORA-54013: INSERT operation disallowed on virtual columns ORA-06512: at line 4

This occurs for only 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();

while WORKORDER table is operating properly!!

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();

I have assured that following:

  • Columns are all IDENTITY with the required ISEQ.
  • Data types for all the Columns are identical in both DBTables and Entites.
  • ORACLE is calculating IDENTITY Property properly (Manual Inserting using ORACLE SQL Developer)
  • 2
    Please [edit] the question to include a [MRE] with the entity definitions (especially how the working entity differs from the other two). If you do not show us the code that you are using then it will be impossible for anyone to help you. – MT0 Jul 10 '23 at 12:04
  • The error is thrown by `SaveChanges`, not `Add`. Add only attaches the object in the `Added` state. You haven't posted your C# classes or even the full exception, so we can only assume what the problem may be. Perhaps one of the classes assigns a value to one of the virtual columns? Post the full exception text, the entities and the DbContext configuration – Panagiotis Kanavos Jul 10 '23 at 13:28
  • @PanagiotisKanavos you are right, SaveChanges() is the one throwing the error! Attached Classes, Tables and Adding Function Code. – Mohamed Reyad Jul 10 '23 at 13:41
  • @MohamedReyad `BDNTIME` is a derived column but you define it as `{ get; set; }` You should not be setting a derived column so you need to look up the documentation of how to implement that. I don't use EF but looking at [this answer](https://stackoverflow.com/a/15585492/1509264) I would assume something like `[DatabaseGenerated(DatabaseGeneratedOption.Computed)] public Nullable BDNTIME { get; private set; }`). – MT0 Jul 10 '23 at 16:00

1 Answers1

1

I'd say that it is not the identity column, but another - virtual column. For example, something like this: see line #7, which is a virtual column?

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.

If I try to insert value into it, Oracle raises error (the same you got):

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

If I omit 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>

Therefore, check whether there's any virtual column in those tables. How? Like this:

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>
Littlefoot
  • 131,892
  • 15
  • 35
  • 57
  • Deffected Tables have another computed (Virtual) Column, however, I am not trying to add any values into them before ading the whole row into the DB. EX: At one of the tables I have the following entities derived from Table class ISSUE { int WORKORDER int QTY decimal PARTPRICE Nullable TOTALPRICE //Calculated - Virtual Column// Nullable REQUESTDATE int ISSUEID //ID Column// } While during adding a new row, I initialise Only the Real Columns not the Virtual! – Mohamed Reyad Jul 10 '23 at 13:05