Don't worry... nobody was offended 2009/10/16 welzie <[email protected]>
> > Thx for the help. I changed the mapping to use <bag> and it worked > fine. I didn't have to change my domain object at all it still > references IList<T>. Note I have lazy loading set to false at the > class level and the <bag> level. > > p.s. I didn't mean to offend anyone by saying I didn't want to use > Iesi.collections. I totally agree .net needs a set, it's a real joke > they don't have one. I was just trying to make the move to nhib a > little easier for some of my developers. > > <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> > <bag name="Accounts" table="user_accounts" lazy="false" > cascade="save-update" generic="true"> > <key column="userid"/> > <many-to-many column="accountid" class="Account"/> > </bag> > <property name="Username"/> > </class> > </hibernate-mapping> > > On Oct 16, 1:36 pm, Fabio Maulo <[email protected]> wrote: > > 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 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
