I wanna get the next automatically incrementing primary key, Here I understood to use T-SQL for doing that.
So I wrote the following method :
public int GetLastNewsID()
{
const string command = @"SELECT IDENT_CURRENT ('{0}') AS Current_Identity;";
int id = EntityModel.ExecuteStoreCommand(command, "News");
return id;
}
but it returns -1, whereas it must be 4 right now.
P.S:
When I execute below T-SQL in SQL Management Studio , it returns 4
USE T;
GO
SELECT IDENT_CURRENT ('NEWS') AS Current_Identity;
GO
You need to use ExecuteStoreQuery
The SQL query will return a
decimalso you need to convert it toint.