I found another useful link about this topic and thought I would
update my question.

http://ayende.com/Blog/archive/2009/04/23/nhibernate-tidbit-ndash-using-ltsetgt-without-referencing-iesi.collections.aspx
>From the above link:
"Some people don’t like having to reference Iesi.Collections in order
to use NHibernate <set/> mapping. With NHibernate 2.1, this is
possible, since we finally have a set type in the actual BCL. We still
don’t have an ISet<T> interface, unfortunately, but that is all right,
we can get by with ICollection<T>.

In other words, any ISet<T> association that you have can be replaced
with an ICollection<T> and instead of initializing it with
Iesi.Collections.Generic.HashedSet<T>, you can initialize it with
System.Collections.Generic.HashSet<T>.

Note that you still need to deploy Iesi.Collections with your
NHibernate application, but that is all, you can remove the
association to Iesi.Collections and use only BCL types in your domain
model, with not external references."


On Oct 16, 3:05 pm, welzie <[email protected]> wrote:
> 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/16welzie<[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

--

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.


Reply via email to