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...
 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Tips

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen

Recent comments

Comment RSS

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in  anyway.

© Copyright 2008