sql - Nhibernate join filtering -


i have question joins in nhibernate. had issue our sql query generated nhibernate. our db developer optimized raw sql works need, need change nhibernate code make generated sql optimized.

the part of original part of query is:

from   person_visit this_                      inner join person_basic per2_                        on this_.person_id = per2_.person_id                      left outer join personc_questions perint10_                        on per2_.person_id = perint10_.person_id                      left outer join telephone_questions intaudit13_                        on perint10_.pp_questions_id = intaudit13_.pp_questions_id                      inner join c_questions intdef14_                        on perint10_.question_id = intdef14_.question_id                           , perint10_.questions_code = intdef14_.questions_code                           , perint10_.question_id = intdef14_.question_id 

the optimized 1 :

from   person_visit this_                      inner join person_basic per2_                        on this_.person_id = per2_.person_id                      left outer join personc_questions perint10_                        on per2_.person_id = perint10_.person_id                      left outer join telephone_questions intaudit13_                        on perint10_.pp_questions_id = intaudit13_.pp_questions_id                      left outer join c_questions intdef14_                        on perint10_.question_id = intdef14_.question_id                           , perint10_.questions_code = intdef14_.questions_code                           , perint10_.question_id = intdef14_.question_id                           , intdef14_.discipline_code = this_.discipline_code 

to change query inner join left outer join easy, changed 1 line of code:

        .createalias("personint.questionentity", "intdef", jointype.leftouterjoin) 

but how can add

                          , intdef14_.discipline_code = this_.discipline_code 

using nhibernate code?

there option add reference person_visit definition c_questions, problem person_visit used everywhere , don't want change possibly break other queries, wnat add 1 line of code add, how can that? there way have access raw join change it? or other way add

                          , intdef14_.discipline_code = this_.discipline_code 

to query? know can add restriction query through criteria.add, not option cause db developer optimized our query taking restriction clause join.

how can without changing models definitions? changing 1 query without changing whole model?

it possible using hql , criteria api's.

this question gives answer: adding conditionals outer joins nhibernate

something may solve issue.

.createalias("personint.questionentity", "intdef", jointype.leftouterjoin,        restrictions.eqproperty("discipline_code", "intdef.discipline_code")) 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -