Get ID for a lazy many-to-one object withot databa

2019-09-14 16:27发布

问题:

I wonder if this is possible,

i have a Class A with Id property of class B connected with lazy many-to-one relation. And i want to get A.B.ID without connecting to database(For sure without loading whole B entity). Is is possible in NhibernatE?

A is many and b is One :)

Thx.

回答1:

Yes this is the default behavior. If you retrieve A from the database then access A.B.Id this will not hit the database. If you access any other property besides the Id field it will cause NHibernate to retrieve B from the database.