[PLSQL] SELECT INTO FROM sequence issue
See original GitHub issueI have a table called THE_TABLE with a sequence configured as next:
[Column("MY_SEQUENCE", DataType = LinqToDB.DataType.Int32, Length = 10, CanBeNull = false, IsPrimaryKey = true, IsIdentity = true)]
[SequenceName("MY_SEQUENCE")]
public new int MY_SEQUENCE{ get; set; }
when I try to do something like:
await _db.OtherTables.Select(x => new MyTable { FOO = x.FOO, BAR = x.BAR, LOREM_IPSUM = x.LOREM_IPSUM }).Into(_db.TheTables).InsertAsync(cancellationToken);
this code is being generated and I cannot find a way to setup the sequence number in the select,
(
MY_SEQUENCE,
FOO,
BAR,
LOREM_IPSUM
)
SELECT
o.FOO,
o.BAR,
o.LOREM_IPSUM
FROM
OTHER_TABLE o`
Exception message:
Stack trace:
Exception: Oracle.ManagedDataAccess.Client.OracleException Message : ORA-00947: not enough values
I tried using Sql.Default<int>() but the ORM is omitting it. For instance:
`await _db.OtherTables.Select(x => new MyTable
{
MY_SEQUENCE = Sql.Default<int>(),
FOO = x.FOO,
BAR = x.BAR,
LOREM_IPSUM = x.LOREM_IPSUM
}).Into(_db.TheTables)
.InsertAsync(cancellationToken);`
will generate the same code in raw sql as above.
I already tried using **InsertWithInt32IdentityAsync** as well but is not working, when I try to do it it's failing with:
Exception: Oracle.ManagedDataAccess.Client.OracleException Message : ORA-00933: SQL command not properly ended
Generating this raw sql:
DECLARE @IDENTITY_PARAMETER Decimal
SET @IDENTITY_PARAMETER = NULL
INSERT INTO THE_TABLE
(
MY_SEQUENCE,
FOO,
BAR,
LOREM_IPSUM
)
SELECT
o.FOO,
o.BAR,
o.LOREM_IPSUM
FROM
OTHER_TABLE o`
RETURNING
MY_SEQUENCE INTO :IDENTITY_PARAMETER
Issue Analytics
- State:
- Created a year ago
- Comments:11 (5 by maintainers)
Will provide answer tomorrow, if no one has solution right now, Such insert needs defining SQL extension method. We do not do any predictions which SQL to generate for
nextval
if user usedSelect
. It is fully custom query and needs custom approach.Anyway, try this simple one:
Closing as there is no response.