K P  Singh Chundawat

K P Singh Chundawat

  • 705
  • 1k
  • 209.4k

How can I get the next Primary Key for SQL 2008 in EF 5

Oct 16 2014 5:47 AM

I am using an Entity Framework 5 connection to connect to a SQL 2008 server R2 to do database handling for my application.

I am using MVC 4 in Visual Studio 2013 and my question is regarding Primary Key fields that are incremented by the SQL itself, is it possible at all for me to be able to find the ID that will be used next by the database.

The reason why I cannot just find the last item and +1 is because if my table contains items 1,2,3,4 and 5, removing item 5 then adding another will make the next item become item 6, rather than 5 again (As I use the Identity Specification in SQL, but this must be used).

I cannot find any method such as Item.ID.GetNextIdentity() or something like that and have looked through as many similar questions like this but to no avail.

Any help would be appreciated

Thanks in Advance
 
Krishanpal Singh