NHibernate.TypeMismatchException: The identifier of the wrong type is provided. Expected: System.Int32, received System.Int64

Use the following query to get a customer. The client has an open identifier of type long.

var client = Session.CreateQuery("from Client as c where c.Id = :Id").SetParameter("Id", 1, NHibernateUtil.Int64).UniqueResult<Client>();

We get the error:

NHibernate.TypeMismatchException: The identifier of the wrong type is provided. Expected: System.Int32, received System.Int64

At the same time, the following works very well.

var client = Session.Get<Client>(1L); //Or
var client = Session.CreateCriteria<Client>().Add(Restrictions.Eq("Id", 1L)).UniqueResult<Client>();

What am I missing? I use free nhibernate to create mappings. I checked the Sqlite and MySql database queries. The same results.

Edit1 . Generating a schema from mappings explicitly uses bigint for the primary key in mysql. That's why I can't figure out what Int32 expects?

Edit2: , Client Report. "--" db , . Report int. , .

:

ClientMap:

HasOne<Report>(x => x.Report)
   .PropertyRef(x => x.Client)
   .LazyLoad()
   .Cascade.SaveUpdate();

ReportMap:

References(x => x.Client, "clientID").Unique();

, , reportid int long. -, , ?

+3

Source: https://habr.com/ru/post/1728264/


All Articles