Id value not retrieved when multi-column PK

Open
#568 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
fsharp, sql
Domain
database

Research direction

Reproduce the F# example with the SillyTable schema against SQL Server, then trace the insert and generated-key retrieval path used by SubmitUpdates() for multi-column primary keys. Done means row.Id contains the database-generated identity value immediately after SubmitUpdates(), matching the value read back from the table.

Written by the indexing model from the issue text.

Description

bug
Description

When a record is inserted in a table that has a multi-column primary key, the Identity value generated is not retrieved.

Repro steps
  1. Create a silly table:
create table SillyTable (TenantId int not null, Id int identity not null)
alter table SillyTable add constraint PK_SillyTable primary key (TenantId, Id)
  1. Insert a row and get the value for Id
let testError () =
        let ctx = sql.GetDataContext()
        let row = ctx.Dbo.SillyTable.Create()
        row.TenantId <- 1
        ctx.SubmitUpdates()
        let id = row.Id //always 0
        let readRow = ctx.Dbo.SillyTable |> Seq.last
        let readId = readRow.Id //return just inserted value (identity)
        (id, readId) //readId has the expected value
Expected behavior

After SubmitUpdates(), the row.Id value should be updated with the value generated by the DB.

Actual behavior

The Id column keeps its default value (0 in this case) after SubmitUpdates()

Known workarounds

None

Related information

Operating System: Windows 10 Pro
Visual Studio: 2017 15.8.1
FSharp.Core 4.5.2
SqlProvider 1.1.48
DB: SqlLocalDB v13

Dominant language
F#
Stars
627
Forks
147
Avg merge
2h 2m
Merged PRs (30d)
1

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from fsprojects/SQLProvider

All issues in fsprojects/SQLProvider

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.