fsprojects / SQLProvider

A general F# SQL database erasing type provider, supporting LINQ queries, schema exploration, individuals, CRUD operations and much more besides.
https://fsprojects.github.io/SQLProvider
Other
564 stars 144 forks source link

Firebird Insert not returning identity column value on SubmitUpdates() #760

Closed kgday closed 2 years ago

kgday commented 2 years ago

Describe the bug Using the firebird provider on a table that has an identity column (a bigint with a before trigger and a number generator) I set up the entity with create, assign the values other than the Id column, call context.SubmitUpdates() but the entity continues to have a zero value. Checking the database confirms the record was inserted correctly with a generated value.

To Reproduce Some code:

[<Literal>]
let dbVendor = Common.DatabaseProviderTypes.FIREBIRD

[<Literal>]
let connStr =
    @"DataSource=localhost;Database=C:\FirebirdDb\machsvc.fdb;User=theUser;Password=pwd;Dialect=3;Pooling=true;"

[<Literal>]
let contextSchemaPath = __SOURCE_DIRECTORY__ + "/dbFirebird.schema"

type db =
    SqlDataProvider<dbVendor, connStr, ResolutionPath=resolutionPath (*ContextSchemaPath=contextSchemaPath,*) , UseOptionTypes=true, CaseSensitivityChange=CaseSensitivityChange.TOLOWER>

let ctx = db.GetContext(runtimeConnectionStr, SelectOperations.DatabaseSide

let domainModel = {(*record creation stuff*)}
let dbRec = ctx.ServiceIntervalType.Create()
DataMapping.ServiceIntervalType.assignToDb domainModel dbRec  //entity is my domain model, dbRec is database record entity
ctx.Db.SubmitUpdates()                
dbRec.Id //returns 0L

I set up the event in my test (xUnit) to give me the sql using: QueryEvents.SqlQueryEvent.Subscribe(fun d -> output.WriteLine(d.ToString()))

The generated sql is

INSERT INTO SERVICE_INTERVAL_TYPE (NAME, DESCRIPTION, INTERVAL_TYPE, DAYS) VALUES (@param0,@param1,@param2,@param3) returning ID; -- params @param0 - "Test Add 1"; @param1 - "Test Service Interval 1"; @param2 - "T"; @param3 - 6; 

Expected behavior The identity column value should be set in the database entity after SubmitUpdates. It works correctly for MySql.

Environment:

kgday commented 2 years ago

Also Firebird 4.0

kgday commented 2 years ago

Thinking about this though, it isn't a true identity column like Firebird 3.0 and up supports but the tradional supplied value from a sequence in a before trigger. Since I want to use FluentMigrator whcih doesn't support Firebird identity columns, I am going to switch to guid and client supplied value.