-->
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.  [ 11 posts ] 
Author Message
 Post subject: helpppppp
PostPosted: Mon Oct 16, 2006 1:02 am 
Regular
Regular

Joined: Mon Aug 28, 2006 6:35 am
Posts: 66
Location: Middle East
Dear users,

Code:
[color=blue][i]when i create an hql session.find ("select dept.name,dept.id from BLL.Department as dept");

i get an ilist to which i can't  bind my gridview -- returning an Ilist with a private member structure ...

how can i solve that !
any ideas ?

can i use an alias such as : session.fin ("select dept.name as Dname , dept.id as Did from BLL.Department as dept"); in order to get a use the alias in my c# code to access my dept.name property ?

it's really urgent :([/i][/color]

10x in advance

jojo

_________________
In Code We Trust


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 16, 2006 1:21 pm 
Regular
Regular

Joined: Thu Aug 24, 2006 2:05 am
Posts: 80
use generics implementation

IQUery queryOJ = session.find("select dept.name as Dname , dept.id as Did from BLL.Department as dept");

IList<string> list = queryOJ.List<String>();
now it will return you name collection and you can use that collection to bind it to datagrid.

Regards
Deepak
If it helps you then dont forget to rate it.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 16, 2006 2:18 pm 
Contributor
Contributor

Joined: Thu May 12, 2005 8:45 am
Posts: 226
Or, you can do a full typesafe object. http://www.hibernate.org/hib_docs/nhibernate/html/queryhql.html#queryhql-select (Be sure to import the type: http://www.hibernate.org/hib_docs/nhibernate/html/mapping.html#mapping-declaration-import)

So, if you have an object "ThinDepartment" with only the Name and ID properties, you could:

Code:
select new ThinDepartment(dept.Name, Dept.ID) from BLL.Department as dept


This gives you an IList that you can cast to ThinDepartment[] which can be databound.


Top
 Profile  
 
 Post subject: Reply : helpppppppppp !
PostPosted: Tue Oct 17, 2006 3:24 am 
Regular
Regular

Joined: Mon Aug 28, 2006 6:35 am
Posts: 66
Location: Middle East
Dear k-dub , deepakbadki

thanks you for your relpies but my pb was not resolved :(

deepakbadki said:
use generics implementation

IQUery queryOJ = session.find("select dept.name as Dname , dept.id as Did from BLL.Department as dept");

IList<string> list = queryOJ.List<String>();
now it will return you name collection and you can use that collection to bind it to datagrid.



Jojorico :
i liked the way you coded but i'm getting several errors in the conversion, the errors are:


line1: IQuery query_retrievedDept = session.Find(hql);
Code:
ERROR: Error   1   Cannot implicitly convert type 'System.Collections.IList' to 'NHibernate.IQuery'. An explicit conversion exists (are you missing a cast?)   C:\Documents and Settings\bacem\Desktop\JAWAD ITECHKEY DAILY REPORTS\DataTutorials\Projects\DataTutorials -- Justin Gehtland\DataTutorials.DLL\DBHandler.cs   307   46   DataTutorials.DLL

line2: retrievedDept = query_retrievedDept.List<string>();
Code:
ERROR:Error   2   The non-generic method 'NHibernate.IQuery.List()' cannot be used with type arguments   C:\Documents and Settings\bacem\Desktop\JAWAD ITECHKEY DAILY REPORTS\DataTutorials\Projects\DataTutorials -- Justin Gehtland\DataTutorials.DLL\DBHandler.cs   308   53   DataTutorials.DLL


Besides, are u using IQUery class other than the NHibernate.IQuery class?

k-dub said:

So, if you have an object "ThinDepartment" with only the Name and ID properties, you could:

select new ThinDepartment(dept.Name, Dept.ID) from BLL.Department as dept


Jojo :
i've used this hql
string hql = "SELECT new DataTutorials.BLL.Department(dept.Name, Dept.ID) from DataTutorials.BLL.Department as dept";

but i'm recieving the following error :


Quote:
Incorrect query syntax [SELECT new DataTutorials.BLL.Department(dept.Name, Dept.ID) from DataTutorials.BLL.Department as dept]
Parameter name: DBHandler - ERROR IN Getting Department Properties
Actual value was NHibernate.QueryException: Incorrect query syntax [SELECT new DataTutorials.BLL.Department(dept.Name, Dept.ID) from DataTutorials.BLL.Department as dept] ---> System.ArgumentException: Item has already been added. Key in dictionary: 'dept' Key being added: 'dept'
at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add)
at System.Collections.Hashtable.Add(Object key, Object value)
at NHibernate.Hql.FromParser.Token(String token, QueryTranslator q)
at NHibernate.Hql.ClauseParser.Token(String token, QueryTranslator q)
at NHibernate.Hql.PreprocessingParser.End(QueryTranslator q)
at NHibernate.Hql.ParserHelper.Parse(IParser p, String text, String seperators, QueryTranslator q)
at NHibernate.Hql.QueryTranslator.Compile()
--- End of inner exception stack trace ---
at NHibernate.Hql.QueryTranslator.Compile()
at NHibernate.Hql.QueryTranslator.Compile(ISessionFactoryImplementor factory, IDictionary replacements, Boolean scalar)
at NHibernate.Impl.SessionFactoryImpl.GetQuery(String queryString, Boolean shallow)
at NHibernate.Impl.SessionImpl.GetQueries(String query, Boolean scalar)
at NHibernate.Impl.SessionImpl.Find(String query, QueryParameters parameters)
at NHibernate.Impl.SessionImpl.Find(String query)
at DataTutorials.DLL.DBHandler.SELECT_PROPERTIES2(String hql) in C:\Documents and Settings\bacem\Desktop\JAWAD ITECHKEY DAILY REPORTS\DataTutorials\Projects\DataTutorials -- Justin Gehtland\DataTutorials.DLL\DBHandler.cs:line 329.

_________________
In Code We Trust


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 17, 2006 5:23 am 
Regular
Regular

Joined: Thu Aug 24, 2006 2:05 am
Posts: 80
Sorry for the wrong reply.
Return type for the session.Find must be IList not IQuery.
If you are using nhibernate 1.2.0 then my solution may help you.

System.Collection.IList<string> s = session.Find

This IList object will contain name collection.

If its not complusory to use "Find" method then you can use ICriteria implementation. This solution will definately help you

ICriteria criteriaObj = session.CreateCriteria( typeof(BLL.Department ));
System.Collections.IList<string> list = criteria.List<string>();

-Regards
Deepak


Top
 Profile  
 
 Post subject: Reply Reply helppppppppppppp
PostPosted: Tue Oct 17, 2006 7:08 am 
Regular
Regular

Joined: Mon Aug 28, 2006 6:35 am
Posts: 66
Location: Middle East
Dear users,

Code:
when i create an hql session.find ("select dept.name,dept.id from BLL.Department as dept");

i get an ilist to which i can't  bind my gridview -- returning an Ilist with a private member structure ...

how can i solve that !
any ideas ?

can i use an alias such as : session.fin ("select dept.name as Dname , dept.id as Did from BLL.Department as dept"); in order to get a use the alias in my c# code to access my dept.name property ?

it's really urgent :(


that must be a common problem ..
p.s:i'm using Nhibernate v1.0.2,

Any help would be really appreciated and rated ;)

10x in advance
jojo

_________________
In Code We Trust


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 17, 2006 2:37 pm 
Regular
Regular

Joined: Thu Aug 24, 2006 2:05 am
Posts: 80
just try wat i ve said in previous reply :)

-Cheers
Deepak


Top
 Profile  
 
 Post subject: Reply
PostPosted: Wed Oct 18, 2006 2:07 am 
Regular
Regular

Joined: Mon Aug 28, 2006 6:35 am
Posts: 66
Location: Middle East
Dear Deepak,

Your reply was :

Quote:
Sorry for the wrong reply.
Return type for the session.Find must be IList not IQuery.
If you are using nhibernate 1.2.0 then my solution may help you.

System.Collection.IList<string> s = session.Find

This IList object will contain name collection.

If its not complusory to use "Find" method then you can use ICriteria implementation. This solution will definately help you

ICriteria criteriaObj = session.CreateCriteria( typeof(BLL.Department ));
System.Collections.IList<string> list = criteria.List<string>();

-Regards
Deepak


First of all i'm using NHibernate v1.0.2
Second, can't cast from IList to IList<string> (System.Collection.IList<string> s = session.Find)!!!
Third, when using the session.CreateCriteria i can't create aliases and use them (such as ur first reply's query), and all the properties(member variables) will be retrieved of the object not some of which is not appropriate in this case .

_________________
In Code We Trust


Top
 Profile  
 
 Post subject: anybody there ?
PostPosted: Thu Oct 19, 2006 3:46 pm 
Regular
Regular

Joined: Mon Aug 28, 2006 6:35 am
Posts: 66
Location: Middle East
hey guys Deepak and k-dub , is there any news ?

_________________
In Code We Trust


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 15, 2006 4:02 am 
Senior
Senior

Joined: Mon Aug 21, 2006 9:18 am
Posts: 179
I may be telling you what you already know, but the query would return a list of object[], where object[0] = id and object[1] = name. I realize this isn't strong-named but why can't you just bind it using, for example, IDBox.Text = '<%# ((object[])Container.DataItem)[0] %>' within your aspx markup?
You can bind an ILIst directly to a GridView.

That's kind of what K-Dub was proposing, except his idea would at least present a strongnamed solution ...same thing tho.

Am I missing something?

_________________
If this helped...please remember to rate it!


Top
 Profile  
 
 Post subject: Re: Reply : helpppppppppp !
PostPosted: Wed Nov 15, 2006 3:52 pm 
Contributor
Contributor

Joined: Thu May 12, 2005 8:45 am
Posts: 226
jojorico wrote:
i've used this hql
string hql = "SELECT new DataTutorials.BLL.Department(dept.Name, Dept.ID) from DataTutorials.BLL.Department as dept";

but i'm recieving the following error :

Code:
Incorrect query syntax [SELECT new DataTutorials.BLL.Department(dept.Name, Dept.ID) from DataTutorials.BLL.Department as dept]
Parameter name: DBHandler - ERROR IN Getting Department Properties 
Actual value was NHibernate.QueryException: Incorrect query syntax [SELECT new DataTutorials.BLL.Department(dept.Name, Dept.ID) from DataTutorials.BLL.Department as dept] ---> System.ArgumentException: Item has already been added. Key in dictionary: 'dept'  Key being added: 'dept'
  at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add)
  at System.Collections.Hashtable.Add(Object key, Object value)
  at NHibernate.Hql.FromParser.Token(String token, QueryTranslator q)
  at NHibernate.Hql.ClauseParser.Token(String token, QueryTranslator q)
  at NHibernate.Hql.PreprocessingParser.End(QueryTranslator q)
  at NHibernate.Hql.ParserHelper.Parse(IParser p, String text, String seperators, QueryTranslator q)
  at NHibernate.Hql.QueryTranslator.Compile()
  --- End of inner exception stack trace ---
  at NHibernate.Hql.QueryTranslator.Compile()
  at NHibernate.Hql.QueryTranslator.Compile(ISessionFactoryImplementor factory, IDictionary replacements, Boolean scalar)
  at NHibernate.Impl.SessionFactoryImpl.GetQuery(String queryString, Boolean shallow)
  at NHibernate.Impl.SessionImpl.GetQueries(String query, Boolean scalar)
  at NHibernate.Impl.SessionImpl.Find(String query, QueryParameters parameters)
  at NHibernate.Impl.SessionImpl.Find(String query)
  at DataTutorials.DLL.DBHandler.SELECT_PROPERTIES2(String hql) in C:\Documents and Settings\bacem\Desktop\JAWAD ITECHKEY DAILY REPORTS\DataTutorials\Projects\DataTutorials -- Justin Gehtland\DataTutorials.DLL\DBHandler.cs:line 329.


To follow my suggestion, you would need to use the custom type you imported, not the same type you have mapped to the database. If you created a ThinDepartment type, use that in the 'new' part of the statement.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 11 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.