1

Possible Duplicate:
Why does select SCOPE_IDENTITY() return a decimal instead of an integer?

I'm using following code to determine last inserted id on my column

var sql = "SELECT IDENT_CURRENT('TableName')"; 
var query = session.CreateSQLQuery(sql); 
var lastInsertedId = query.UniqueResult(); 

But when I'm try to use these id value

photo.Property = session.Load<Domain.Property>(lastInsertedId);

I got following error message Provided id of the wrong type. Expected: System.Int32, got System.Decimal

How can I overcome these ? Thanks

Community
  • 1
  • 1
panjo
  • 3,467
  • 11
  • 48
  • 82

2 Answers2

3

lastInsertedId is getting returned as decimal you will have to convert it into to Int and pass it to the session.Load method

photo.Property = session.Load<Domain.Property>(System.Convert.ToInt32(lastInsertedId)); 
HatSoft
  • 11,077
  • 3
  • 28
  • 43
0

You can write:

SELECT Cast(IDENT_CURRENT('Core.Clients') As Int)
Chepene
  • 1,128
  • 1
  • 12
  • 18