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.  [ 5 posts ] 
Author Message
 Post subject: How to convert ISet<T> to System.Collection.Generic IL
PostPosted: Sat Jun 17, 2006 12:48 pm 
Newbie

Joined: Sat Jun 17, 2006 12:43 pm
Posts: 5
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

NHibernate Version 1.2.0 Alpha


HI,

I am new to NHibernate (as well as .net) but I've managed to get the stuff working. I can extract and persist data. I am using Set to map one-to-many relations. But when using it in the application, I want to be able to convert ISet to IList.

Is there any way to do this?

Also, How to use Attributes to map (thus avoiding hbm.xml files) in NHibernate. Please point me to any articles if possible.

Many thanks,

Sath


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 19, 2006 11:13 am 
Newbie

Joined: Sat Jun 17, 2006 9:44 am
Posts: 6
As far as I know the ISet collection implements the following interfaces:

- ICloneable
- ICollection
- IEnumerable

This means you won't be able to cast it to an IList.


Top
 Profile  
 
 Post subject: Re: How to convert ISet<T> to System.Collection.Generi
PostPosted: Mon Jun 19, 2006 12:32 pm 
Newbie

Joined: Fri Mar 24, 2006 3:45 pm
Posts: 18
Hi Sath,

About your first question:

First I would recomend that you analyze first if the most correct mapping for your collection would be a List instead of a Set.

If the mapping really is a Set a solution (usefull for databinding) could be:

Code:
IList<T> aList = new List<T>(yourSet)


This method initializes a new list with the elements in the set (it copies all elements) (if you need to databind your set this could be an option):

Code:
aGridControl.DataSource = new List<T>(yourSet)


Hope this helps.

Hector Cruz


Top
 Profile  
 
 Post subject: Code doesnot work
PostPosted: Mon Jul 03, 2006 4:15 pm 
Newbie

Joined: Sat Jun 17, 2006 12:43 pm
Posts: 5
Hi,

Thanks for your reply, but the code does not work. It won't convert. Error: Best overload method for List<T> (int). Cannot cast Iesis... ... set to int.

If you are aware of a solution, please do share.

regards,

Sath


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 04, 2006 1:42 am 
Regular
Regular

Joined: Wed Jun 21, 2006 3:13 pm
Posts: 110
Instead of a set, is it possible to use a bag? Then you can use the IList from the back-end all the way through.

Otherwise, try this.. haven't tested, but it's what the Intellisense gives as an option:

Code:
IList<T> aList = new List<T>((IEnumerable<T>)yourSet)


List<T> wants an empty constructor, an initial size (int constructor) or a collection that supports IEnumerable<T>. The set should do that. (I think ISet<T> supports IEnumerable<T>).

So, cast your set to an enumerable and see if it works...


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