so, situation. have c# project uses nhibernate 3.3 (upgrading not option), following classes:
public class person{ public list<personaddress> personaddresses {get;set;} } public class naturalperson : person{ public naturalproperty naturalproperty {get;set;} } public class legalperson : person{ public legalproperty legalproperty {get;set;} } public class quarantine{ public person quarantineperson {get;set;} public quarantineproperty quarantineproperty {get;set;} } what need obtain persons may or not "be in quarantine" , satisfy different conditions involve quarantine's properties, , legal or natural properties. need left join persons, or right join quarantines:
select * quarantine q right join persons p on p.id = q.quarantinepersonid left join naturalpersons np on p.id = np.id left join legalpersons lp on p.id = lp.id q.property = 1 , np.property = 1 this have now. have managed "from" clause need, i'm having serious problems "select" , "where" clauses:
person p = null; quarantine q = null; var results = this.session.queryover<quarantine>(() => q) .joinqueryover<person>(() => q.quarantineperson, () => p, jointype.rightouterjoin) .selectlist(list => list .select(() => p.id)) .transformusing(transformers.aliastobean<person>()) .list<person>(); this code generates following query:
`select p1_.personid y0_ bup.quarantines this_ right outer join bup.persons p1_ on this_.quarantinepersonid = p1_.personid left outer join bup.legalpersons p1_1_ on p1_.personid = p1_1_.personid left outer join bup.naturalpersons p1_2_ on p1_.personid = p1_2_.personid` as said, "from" clause ok. problem select , clauses.
the main problem select need whole person object, wether it's legal or natural person. have tried removing .selectlist query, throws propertynotfoundexception: "could not find setter property 'p' in class 'person'".
and problem clause don't know how add conditions based on naturalperson , legalperson's properties. have no problem filtering quarantine , person properties, haven't yet succedeed same other classes.
also, query should performant possible, because timeout serious problem. have managed other solutions subqueries , such, took long.
any help, of 2 issues, appreciated!
thanks!!
you can use subqueries mixing future execute both queries in 1 row trip:
var subquery = queryover.of<quarantine>() .select(x => x.quarantineperson.id); var naturalpersons = session.queryover<naturalperson>() .withsubquery.whereproperty(x => x.id).notin(subquery) //.where(x => x.naturalproperty == somehing) .future(); var legalpersons = session.queryover<legalperson>() .withsubquery.whereproperty(x => x.id).notin(subquery) //.where(x => x.legalproperty == somehing) .future(); var persons = naturalpersons.cast<person>().union(legalpersons);
Comments
Post a Comment