Many to many lazzziii
I scratched my head for a few hours reading between the line of the following code
DetachedCriteria filter = DetachedCriteria.For(typeof(Project))
.Add(Expression.Eq("ID", pid))
.SetProjection(Projections.Property("Type"));
DetachedCriteria q = DetachedCriteria.For(typeof(List_Output), "op")
.CreateCriteria("ProjectTypes")
.Add(Subqueries.Exists(filter));
ISession s = holder.CreateSession(typeof(List_Output));
IList result;
try{
result = q.GetExecutableCriteria(s).List();
}finally{
holder.ReleaseSession(s);
}
Wonder why It generate so many sql call to the server? the domain objects in discussion are Project which belong to a Type and base on selected Type a project can choices a bunch of Outputs.
So Project is belong to a Type [One-to-Many], and Type has many Outputs where Output belong to Many Types [Many-to-Many].
After a while I found the issue and got it fixed “it is the Lazzzzzzzziiiiiiiiiiiiiiiines” configuration :))
I forgot to tell Type to load Outputs in a Lazy mode and vise versa, once configured I got only one YEAH ! I mean ONE (a single) sql call to the server instead of 2 + N (where N is number of relevant Outputs in a Type)
Thanks to DetachedCriteria & the Laziness until next time don’t forget the magic word is “Lazy = true”
