How to run Nhibernate ICriteria query with setFetchMode(Lazy) when lazy=false defined in HBM?
I'd like to run a criteria query with lazy many-to-one associations. Those associations are set as lazy="false"
in the HBM. It's because we use it eagerly 90% of the project.
But there are a few 'big' queries that should run as lazy="proxy"
.
HBM:
<many-to-one name="DestinationElement" class="X" column="DstElemId" not-null="true" unique="false" cascade="save-update" outer-join="auto" fetch="select" lazy="false" index="IDX_Ass_DestElem">
Criteria setup:
criteria.SetFetchMode("DestinationElement", FetchMode.Lazy);
I开发者_如何学Got works the opposite way, but not this way. It fetches eagerly.
The LOC is 20K+, and it'd be a massive refactor to do it the opposite way.
How can I force this to fetch lazily only when I want, and fetch eagerly all other times?
Thanks in advance!
lazy="false"
in the HBM cannot be overriden in a query (besides being a bad idea 99% of the time)
You'll have to change your code.
精彩评论