-->
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.  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Bag vs IList
PostPosted: Wed Mar 22, 2006 3:53 pm 
Regular
Regular

Joined: Fri Feb 03, 2006 5:28 pm
Posts: 73
Location: Québec, QC, Canada
Hi everyone,

I've been using NHibernate for 2 weeks now.. and I must say it saves me a hell lot of a time! I just love it !

So far, to represent one-to-many relation, i currently use <bag> in my mapping files and an IList (ArrayList) in my code. So far so good.

But let's say I have a Customer object with an Orders collection

I have to cast it like this:

((Order)Customer.Orders[1]).DateOrdered
I would like to have this instead:

Customer.Orders[1].DateOrdered


Is there an easy way to do this, not using Iesi collection? If not, which class in Iesi collection should I use?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 22, 2006 7:03 pm 
Newbie

Joined: Mon Jan 30, 2006 6:33 pm
Posts: 9
If you're using .NET 2.0 try generic collections:

IList <Order> GetOrders(...)

Please correct me, if this isn't the right syntax.

If you're using a previous version I think you have to cast for your class.


Top
 Profile  
 
 Post subject: Cast the object
PostPosted: Thu Mar 23, 2006 11:35 am 
Newbie

Joined: Sat Feb 25, 2006 3:30 pm
Posts: 13
I second the last response.

Items in your collection are anonymous when extracting them from teh collection. They must be cast to the correct type in order to access their members.

You could derive a class from ArrayList (or another Collection class) and override the Add and the indexer to only allow Customer objects in and out. That would give you the symantics you are looking for.

Thanks,
Steve Brennan


Top
 Profile  
 
 Post subject: Re: Cast the object
PostPosted: Thu Mar 23, 2006 11:42 am 
Regular
Regular

Joined: Fri Feb 03, 2006 5:28 pm
Posts: 73
Location: Québec, QC, Canada
sbrennan wrote:
You could derive a class from ArrayList (or another Collection class) and override the Add and the indexer to only allow Customer objects in and out. That would give you the symantics you are looking for.

Thanks,
Steve Brennan


Thanks, that's exactly what I wanted..

the IList<type> doesn't work yet with Nhibernate!

Thanks to both of you!


Top
 Profile  
 
 Post subject: Re: Cast the object
PostPosted: Thu Mar 23, 2006 2:09 pm 
Newbie

Joined: Sat Feb 25, 2006 3:30 pm
Posts: 13
martbl wrote:
sbrennan wrote:
Thanks, that's exactly what I wanted..

the IList<type> doesn't work yet with Nhibernate!

Thanks to both of you!

Could you rate my post, I am down to 8 points.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 23, 2006 7:33 pm 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
You may want to take a look at Ayende's NHibernate.Generics - they certainly solved my strong-typing problems.

http://www.ayende.com/projects/nhiberna ... erics.aspx

Cheers,

Symon.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 24, 2006 4:38 am 
Senior
Senior

Joined: Thu Aug 25, 2005 3:35 am
Posts: 160
actually, if you just retrieve the latest version of nH through subversion, you have generics by nh. It's not a fullly tested implementation, but works for me.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 24, 2006 8:27 pm 
Regular
Regular

Joined: Fri Jan 27, 2006 2:32 pm
Posts: 102
Location: California, USA
TheShark wrote:
actually, if you just retrieve the latest version of nH through subversion, you have generics by nh. It's not a fullly tested implementation, but works for me.


Really? Are you building it yourself from SVN? Is it that hard? I remember reading something about ILMerge being used to build NHibernate.

I tried to get the source from SourceForget, but halfway through i get an error.

I tried to get the nightly build, but the CruiseControl server says it failed to build.

--Brian


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 24, 2006 11:31 pm 
Regular
Regular

Joined: Fri Feb 03, 2006 5:28 pm
Posts: 73
Location: Québec, QC, Canada
yeah,.. I'd like to know how to get it from subversion and compile it!

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 25, 2006 9:19 am 
Senior
Senior

Joined: Thu Aug 25, 2005 3:35 am
Posts: 160
no, the ilmerge step was removed.. just get from sourceforge again and compile.. no problems with that.

did that help?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 25, 2006 11:54 am 
Contributor
Contributor

Joined: Thu May 12, 2005 8:45 am
Posts: 226
... not that the use of ilmerge prevented NH from building. :)

If you have NAnt, you can build NHibernate like a pro! ;)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 27, 2006 12:51 am 
Beginner
Beginner

Joined: Thu Dec 08, 2005 6:49 pm
Posts: 49
Quote:
If you have NAnt, you can build NHibernate like a pro! ;)

What if you don't have Clover installed?

Code:
Assembly "C:\Program Files\Cenqua\Clover.NET for Visual Studio\CloverNAnt-0.85.dll" does not exist
. Can't scan for extensions.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 27, 2006 2:00 am 
Contributor
Contributor

Joined: Thu May 12, 2005 8:45 am
Posts: 226
What version of nant are you using? What command are you using to build? I call "nant clean build test" and it doesn't need clover (which I do not have installed) to build successfully.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 27, 2006 3:27 am 
Beginner
Beginner

Joined: Thu Dec 08, 2005 6:49 pm
Posts: 49
Cheers, that did the trick. I was running debug.bat.

After a quick look, why is there no PersistentGenericSet class? There seem to be a few ISet<T> implementations floating around...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 10, 2006 1:47 pm 
Regular
Regular

Joined: Fri Feb 03, 2006 5:28 pm
Posts: 73
Location: Québec, QC, Canada
I created a class that derive from BaseCollection called CategoryCollection.

When I try to retrieve an object which has a property of type CategoryCollection, I get the following:

Object of type 'NHibernate.Collection.Bag' cannot be converted to type 'Com.Progmatik.ClickMax.CategoryCollection'.


The mapping for this uses a Bag as the error Suggest..

Any help ?


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

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.