-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Not Exist sql query in Nhibernate (ActiveRecordLinqBase)
PostPosted: Thu Dec 09, 2010 7:41 am 
Newbie

Joined: Thu Dec 09, 2010 7:31 am
Posts: 2
Hello i'm trying to convert this query into nhibernate... .

Can some help me out?
the qry directly on the db (oracle database):
Code:
SELECT DISTINCT * FROM APPLICATION.PATIENT P join admission a on p.patientkey = a.patientkey
            WHERE not exists (select  * from document d  where d.patientkey = p.patientkey  and d.rubriccode = '0100101003') and a.patientclass = 'I' and a.admissiondate BETWEEN  to_date('20090101','yyyymmdd') and to_date('20100401','yyyymmdd') order by p.patientkey;



This is my try on the ActiveRecordLinqBase
Code:
IEnumerable<Patient> pat = (from patient in ActiveRecordLinq.AsQueryable<Patient>()
                                       from adm in patient.Admissions                           
                                       where !(from doc in ActiveRecordLinq.AsQueryable<Document>() where doc.RubricCode.Equals("0100101003") select doc.PatientKey).Contains(patient.PatientKey) && adm.PatientClass.Equals("I") && adm.AdmissionDate >= new DateTime(2009, 01, 01) && adm.AdmissionDate <= new DateTime(2010, 01, 01)
                                       select patient).Distinct();


The query without the ! contains operator works fine... . The error is :
error:
Code supposed to be unreachable
STack:
Code:
   at System.Linq.Expressions.Compiler.StackSpiller.RewriteExpression(Expression node, Stack stack)
   at System.Linq.Expressions.Compiler.StackSpiller.ChildRewriter.Add(Expression node)
   at System.Linq.Expressions.Compiler.StackSpiller.ChildRewriter.AddArguments(IArgumentProvider expressions)
   at System.Linq.Expressions.Compiler.StackSpiller.RewriteMethodCallExpression(Expression expr, Stack stack)
   at System.Linq.Expressions.Compiler.StackSpiller.RewriteExpression(Expression node, Stack stack)
   at System.Linq.Expressions.Compiler.StackSpiller.ChildRewriter.Add(Expression node)
   at System.Linq.Expressions.Compiler.StackSpiller.ChildRewriter.AddArguments(IArgumentProvider expressions)
   at System.Linq.Expressions.Compiler.StackSpiller.RewriteMethodCallExpression(Expression expr, Stack stack)


Thx for the help!


Top
 Profile  
 
 Post subject: Re: Not Exist sql query in Nhibernate (ActiveRecordLinqBase)
PostPosted: Thu Dec 09, 2010 7:54 am 
Newbie

Joined: Thu Dec 09, 2010 7:31 am
Posts: 2
Found a solution :)

Code:
var qry = (from doc in ActiveRecordLinq.AsQueryable<Document>() where doc.RubricCode.Equals(typeDocument) select doc.PatientKey).ToArray();
            return (from patient in ActiveRecordLinq.AsQueryable<Patient>()
                    from adm in patient.Admissions
                    where !qry.Contains(patient.PatientKey) && adm.PatientClass.Equals("I") && adm.AdmissionDate >= startDate && adm.AdmissionDate <= endDate
                    select patient).Distinct();


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.