NHibernate error : identifier type mismatch

by Mathieu 15. July 2008 20:34

If your entity has an id type of long, and you try to get it with ISession.Get<T>( 123 ), it will pass 123 as an int, and the following exception is thrown :

System.ArgumentException : identifier type mismatch
Parameter name : id

You can use ISession.Get<T>( (long)123 ), but it's not very clean. And it has caused some hair pulling to me :)

An alternative is to use :

id = Convert.ChangeType( id, typeof(T).GetProperty("Id").PropertyType);

ISession.Get<T>( id );

but still not very clean...
 

Tags:

Tips

Comments

8/8/2008 10:01:24 PM #

Gustavo Melo

Great News.
I have this problem, i now it's solved.
Thx ver much

Gustavo Melo Brazil

Powered by BlogEngine.NET 1.5.0.7
Theme by Mads Kristensen