Another alternative for IList collections, is to use <bag> in your mappings.
On Fri, Oct 16, 2009 at 3:44 PM, Fabio Maulo <[email protected]> wrote: > Use ICollection<T> and <set> > btw I don't understand all those "NOT". > MS has understand that we need a Set semantic in C#3.0 and then they > understand that we need ISet (interface) in C#4.0 (program to interface not > to implementation). > > A dependency to Iesi.Collection is a dependency to something should be in > the .NET FX and is not evil. > > > > 2009/10/16 Fabio Maulo <[email protected]> > >> If you want use <set> you should use ISet in the classif you want use >> IList you should use <bag> in the mapping. >> >> 2009/10/16 welzie <[email protected]> >> >> >>> I'm sure this gets asked all the time but here goes. I am having >>> problems figuring out how to nhib to populate a collection of >>> objects. I do NOT want to use the Iesi.collections. I do NOT want to >>> introduce a dependency on those classes throughout my application. >>> >>> Is there anyway to get nhib to populate a collection with an >>> implementation of System.Collections.Generic.IList<T>? Surely there >>> is a solution to this or does everyone just reference >>> Iesi.Collection.ISet throughout their apps? >>> >>> Below is the error I get when nhib tries to populate the Accounts >>> property of the User class. I am using nhib 2.1.0GA. (Account mapping >>> and class not shown) >>> >>> ERROR: >>> System.InvalidCastException : Unable to cast object of type >>> 'NHibernate.Collection.Generic.PersistentGenericSet`1 >>> [ClaimAudit.Entity.Account]' to type >>> 'System.Collections.Generic.IList`1[ClaimAudit.Entity.Account]'. >>> >>> MY CLASS: >>> using System.Collections.Generic; >>> public class User >>> { >>> public virtual int Id {get; set;} >>> private IList<Account> accounts = new List<Account>(); >>> public virtual IList<Account> Accounts {get{return accounts;} >>> set{accounts = value;}} >>> public virtual string Username {get; set;} >>> } >>> >>> MAPPING: >>> <?xml version="1.0" encoding="utf-8" ?> >>> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" >>> assembly="Entity" >>> namespace="ClaimAudit.Entity"> >>> <class name="ClaimAudit.Entity.User" lazy="false" table="users"> >>> <id name="Id"> >>> <generator class="native"/> >>> </id> >>> <set name="Accounts" table="user_accounts"> >>> <key column="userid"/> >>> <many-to-many column="accountid" class="Account"/> >>> </set> >>> <property name="Username"/> >>> </many-to-one> >>> </class> >>> </hibernate-mapping> >>> >>> >>> >> >> >> -- >> Fabio Maulo >> > > > > -- > Fabio Maulo > > > > -- Humberto C Marchezi --------------------------------------------------------- Master in Electrical Engineering - Automation Software Consultant and Developer at the Town Hall of Vitória --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nhusers?hl=en -~----------~----~----~----~------~----~------~--~---
