entity-framework-coreoracle11glinqpad

ExecuteQuery method is missing when using Oracle Provider 7.12 + EF Core 7 on LinqPad


I need to retrieve a sequence value to use when adding new records on table PERSON. The pure SQL to do this is:

SELECT SEQ_PERSON_ID.NEXTVAL FROM DUAL

I tried to use this code:

var newID = this.ExecuteQuery<decimal>("SELECT SEQ_PERSON_ID.NEXTVAL FROM DUAL").First();

But I'm told ExecuteQuery is unknown.

This an Oracle 11 database. I use LinqPad 7. Connection provider is Oracle 7.21.12 latest. Entity Framework Core is v7.0.3.

How can I get the latest incremental value of PERSON_ID in a LinqPad program?


Solution

  • Since there is no ExecuteSql or similar methods I just inserted a new view which retrieves the newest ID.

    Oracle doesn't support below as view:

    CREATE OR REPLACE VIEW VIEW_NEXT_ID AS SELECT SEQ_PERSON_ID.NEXTVAL AS NEXT_ID FROM DUAL
    

    So first I created a table function:

    CREATE OR REPLACE FUNCTION GET_NEXT_PERSON_ID
    RETURN SYS.ODCINUMBERLIST PIPELINED IS
    BEGIN
       PIPE ROW (SEQ_PERSON_ID.NEXTVAL);
       RETURN;
    END;
    

    And then the view like:

    CREATE OR REPLACE VIEW VW_GET_NEXT_PERSON_ID AS SELECT COLUMN_VALUE AS NEXT_ID FROM TABLE(GET_NEXT_PERSON_ID())
    

    And the C# code in LinqPad:

    var nextVal = VwGetNextPersonID.FirstOrDefault();
    var newID = (int)nextVal.NextID;