-->
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: CreateSqlQuery
PostPosted: Sun Jun 10, 2007 4:59 pm 
Newbie

Joined: Wed Mar 21, 2007 9:45 am
Posts: 3
NHibernate version: 1.2

I have a problem with CreateSqlQuery.
my sql query (that works is) :

select * from dbo.Enrollments as e where
e.LectureId in
(select l.Id from dbo.Lectures as l where l.TeacherId=2)

i was able to get the first select running, the code is :

string queryStr = "select {E.*} from Enrollments {E} where {E}.LectureId = 2";
IQuery query = _session.CreateSQLQuery(queryStr, "E", typeof(Enrollment));

can anyone please tell me how to write the whole query.

what i have written so far is :

string queryStr = "select {E.*} from Enrollments {E} where {E}.LectureId in ( select {L}.Id from Lectures {L} where {L}.TeacherId=" + _request.TeacherId + " )";

i have tried also with :
IQuery query = _session.CreateSQLQuery(queryStr, new string[] { "E", "L" }, new Type[] { typeof(Enrollment), typeof(Lecture)

Exception MESSAGE is : Incorrect syntax near '}'.

thank you,
Horea


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 11, 2007 12:54 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Since you aren't actually retrieving any lectures, you don't need to use {L} but instead you can use just the table name, i.e. select {E.*} from Enrollments {E} where {E}.LectureId in (select l.Id from dbo.Lectures as l where l.TeacherId=2).


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.