DapperAOT

DAP203

@@identity is the global identity function, and returns the last-inserted identity value; it is considered deprecated and actively harmful, as it is very hard to predict what value it represents, especially when things like triggers are in play. It is also limited to a single value, where-as insert can be multi-row.

You should use SCOPE_IDENTITY() instead of @@identity, or (preferably) use the OUTPUT clause.

Bad:

insert SomeTable (A) values (1)
select @@identity

Better:

insert SomeTable (A) values (1)
select SCOPE_IDENTITY()

Best:

insert SomeTable (A)
output inserted.Id
values (1)