Reputation: 311
I have following class:
public class PurchaseOrder
{
...
Store Store { get; protected set; }
User CreatedBy { get; protected set; }
User ApprovedBy { get; protected set; }
...
}
User and Store classes are mapped with lazy="false" option.
<class name="User" lazy="false">
More to say them associated to some other entities that mapped with lazy="false"
option. And I am not allowed to change it. It's not "my" classes, them belongs to other domains.
My problem that every time that I fetch PurchaseOrder it produces additional queries for those classes and their dependencies leading me to SELECT N+1 problem. In 99% of cases I do not need all that information - store id and user id is enough for me. Tried to use ...
session.CreateCreteria<PurchaseOrder>()
...
.SetFetchMode("CreatedBy", FetchMode.Lazy)
.SetFetchMode("ApprovedBy", FetchMode.Lazy)
.SetFetchMode("Store", FetchMode.Lazy)
...
.. but it does not help.
How can I force those associations to be lazy and to ignore lazy="false"
?
Just to be clear. The information that stored in User and Store classes is useless for my domain. So I do not want it to be fetched at all. Also if I join users and stores in my query it will lead to chain of queries for entities that also mapped as lazy="false" (do not ask why, I can't change it). I aligned to some company's standard and must reference those classes (I do not like it but this is a rule), but I do not want to fetch their data, i want it lazy.
Upvotes: 0
Views: 151
Reputation: 52735
You can't override lazy="false"
.
What you can do is the exact oposite of what you did: fetch eagerly (FetchMode.Eager
or FetchMode.Join
, which are synonyms).
Upvotes: 2