-->
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.  [ 3 posts ] 
Author Message
 Post subject: General IList or typed Collection ?
PostPosted: Wed Mar 29, 2006 7:31 am 
Newbie

Joined: Wed Mar 29, 2006 5:04 am
Posts: 9
Location: Antwerp, Belgium
I'm using a tool that generates a NHibernate-mappingfile, and all classes I need, based upon a database. The tool gives me a choise to implement collection-properties as IList or as typed collection. e.g. a property Orders can look like this :
public IList Orders {...}

or

public OrdersCollection Orders {...}

In the latter case, the tool also constructs the OrdersCollection-class.
Now what should I use ? Since I'm lazy=true, I prefer the IList. I tried to find what are the best practices, but didn't find anything. Any suggestions ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 30, 2006 8:36 am 
Beginner
Beginner

Joined: Wed Aug 10, 2005 6:21 pm
Posts: 24
Location: Antwerp, Belgium
Actually, Sergey has just made the new documentation available.
It's well worth a read.

For instance, in section 6.1 (Persisent Collections) it says:

Quote:
Furthermore, the type of a property holding a collection
must be the interface type (ie. IDictionary, ISet or IList; never
Hashtable, SortedSet or ArrayList). This restriction exists because,
when you're not looking, NHibernate sneakily replaces your
instances of IDictionary, ISet and IList with instances of its own
persistent implementations of IDictionary, ISet or IList. (So also be
careful when using == on your collections.)


Consult the sticky announcement at the top of the topic list
in the NHibernate forum to find the documentation.

HTH

Sven


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 30, 2006 1:23 pm 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
If you use internal accessors then they can be IList and you can use a strongly typed collection for your public properties if you want to limit the type of data that the object consumer can add to the collection.

Originally I created a whole bunch of strongly typed collections (which were more than a bit of pain) and then I moved to .NET 2.0. Once I did that I grabbed Ayende's Generics assembly (http://www.ayende.com/projects/nhiberna ... erics.aspx) and used generic collections.

This solution worked really well for me.

Symon.


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