I'm working on a online store. I keep the added items in the cookies and at the time of check out, I place the order in the database. In my DB I have two tables orders
, orderItems
.
Order:
[Order_Id] INT IDENTITY(1,1) NOT NULL PRIMARY KEY,
[Customer_Id] INT --FK--
....
OrderItems
[Order_Id] INT --FK to Order--
[Item_Id] INT --FK to Item table--
When I place the order first in order table I need the Order_Id
to be able to properly place items for the order. I know that SCOPE_IDENTITY
would give me the last identity in the table but I think this might cause some concurrency problem. I'm using EF6 so I'm not sure even if I can use the SCOPE_IDENTITY
but even though I can I'm still concerned about the concurrency problems.
What I wanna know is how to get the auto-incremented identity right after the insert ?
I'm using EF 6 as ORM and the website is written in ASP.NET MVC C#.