In transaction, @@IDENTITY return other table id, is it a bug?
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 18.4k
- Forks
- 3.7k
- Avg merge
- 5h 8m
- Merged PRs (30d)
- 1
Description
My project use:
Dapper 1.50.2
Dapper.Contrib 2.0.0
DapperExtensions 1.6.3
and my code like this:
var sql = "insert into tb(name) select 'aaa' from dual where not exists(select 1 from tb where name='aaa')";
using(var connection = factory.CreateConnection())
using(var trans = connection.BeginTransaction())
{
if(connection.Execute(sql, null, trans) > 0)
{
return Convert.ToInt64(connection.ExecuteScalar("SELECT @@IDENTITY", null, trans));
}
}
return 0;
while I published the code, I found "SELECT @@IDENTITY" returns other table's autoId, not tb's autoId?
Is my code wrong? how to fix it?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by identifying the database provider returned by factory.CreateConnection and reproduce the transaction using the SQL shown in the issue. Check whether the provider's @@IDENTITY behavior accounts for the returned value; done means establishing whether Dapper is involved and documenting a confirmed fix or limitation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, sql
- Domain
- database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100