-->
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.  [ 6 posts ] 
Author Message
 Post subject: Problem with the query 11.13. Tips & Tricks
PostPosted: Mon Apr 10, 2006 12:05 pm 
Newbie

Joined: Mon Apr 10, 2006 11:59 am
Posts: 9
Hi all,
before posting I checked the documentation a copule of times.
And I'm confused, I try something very similar to the code segment bellow, however this can't even compile on .NET.

Code:
IEnumerable countEn = session.Enumerable("select count(*) from ....");
countEn.MoveNext();
int count = (int) countEn.Current;


I Get an error with something like: "Error 1 'System.Collections.IEnumerable' does not contain a definition for 'MoveNext'", Which is correct, only the interface IEnumerator have
those definitios.

Any idea if this is a bug ? Do we really have this code working on .NET or something similar to it ?

Thanks in advance for your help.
Best reagards

Luis de Sousa


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 10, 2006 12:56 pm 
Regular
Regular

Joined: Tue Mar 15, 2005 12:38 pm
Posts: 73
Location: Bucharest
Try:

IEnumerable enumerable = session.Enumerable("select count(*) from ....");
IEnumerator en = enumerable.GetEnumerator();
en.MoveNext();
int count = (int) en.Current;

(the IEnumerable interface allows you to create an enumerator).

Dragos


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 10, 2006 5:49 pm 
Newbie

Joined: Mon Apr 10, 2006 11:59 am
Posts: 9
Hi Dragos,

I tried your approach and it worked correctly.
When working under to much pressure, some times we miss what
is right in front of our eyes!
Anyway the documentation must be corrected.
Thanks for the help, regards

Luis Filipe de Sousa


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 08, 2006 8:06 am 
Newbie

Joined: Fri May 05, 2006 11:27 am
Posts: 8
Hello!
I tried something like this:

dado2003 wrote:
Try:

IEnumerable enumerable = session.Enumerable("select count(*) from ....");
IEnumerator en = enumerable.GetEnumerator();
en.MoveNext();
int count = (int) en.Current;

(the IEnumerable interface allows you to create an enumerator).

Dragos


In particular I tried:
IEnumerable enu = session.Enumerable(" from Order myOrder");

but when compiling I received this error:
Using the generic type 'System.Collections.Generic.IEnumerable<T>' requires '1' type arguments

So I assume there is something I don't know about generic in .NET 2.0....
Anyway I tried something like this:

IEnumerable<Order> enu = session.Enumerable(" from Order myOrder");

But received:
Cannot implicitly convert type 'Examples.Northwind.Order' to 'System.Collections.Generic.IEnumerable<Examples.Northwind.Order>'. An explicit conversion exists (are you missing a cast?)


Then I tried to cast it to the Order class:

IEnumerable<Order> enu = (Order) session.Enumerable(" from Order myOrder");

But then I had:
Cannot implicitly convert type 'Examples.Northwind.Order' to 'System.Collections.Generic.IEnumerable<Examples.Northwind.Order>'. An explicit conversion exists (are you missing a cast?)

What hell do I have to do for this should work?

Thanks in advance!
ema[/b]


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 08, 2006 8:27 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
emanuele.ornella wrote:
In particular I tried:
IEnumerable enu = session.Enumerable(" from Order myOrder");

but when compiling I received this error:
Using the generic type 'System.Collections.Generic.IEnumerable<T>' requires '1' type arguments


Try

System.Collections.IEnumerable enu = session.Enumerable(" from Order myOrder");

Gert


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 08, 2006 10:01 am 
Newbie

Joined: Fri May 05, 2006 11:27 am
Posts: 8
Ok, it worked!
I feel a bit stupid about this problem ;-) but I knew it was something very easy !!



System.Collections.IEnumerable enu = session.Enumerable(" from Order myOrder");

[/quote]

Thanks Gert!
ema


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