The problem here is imho NHibernate itself, which doesn't allow you to define custom collections, or implementations of interfaces, without providing a custom implementation of the mind-blowingly large and horrible interface "IUserCollectionType".

There should be a way to say "use NHibernate's lazy loading and database access stuff, but please let me implement everything else in this interface, thank you". Perhaps this could be done via a base class implementation of IUserCollectionType that exposes some of the methods as unimplemented and abstract? I don't know as I haven't tried.

It would be awesome if NHibernate could allow you to only implement everything you extend from the base collection interfaces, or override implementations on a method-by-method basis. Often, I'd just like to override the "Add" method, for instance, to be able to set both ends of a one-to-many or many-to-many relation when adding new (unsaved) entities.

This level of fine-grained extensibility is afaik not possible with NHibernate's collections; it's all or nothing if you want to do something custom.


-Asbjørn


On Tue, 06 Jul 2010 16:07:45 +0200, Paul Batum <paul.ba...@gmail.com> wrote:

Unfortunately C# is a leaky umbrella - its impossible to always stay DRY
with it :)

There might be some tricks using other tools such as PostSharp that can
address these sorts of problems but I haven't really investigated it.

On Tue, Jul 6, 2010 at 11:37 PM, mynkow <myn...@gmail.com> wrote:

Yes, this is an option. But I am trying to stay DRY. I have many
collections and I will be forced to write those line many times. Any
idea how to do it DRY

On Jul 6, 3:07 pm, Paul Batum <paul.ba...@gmail.com> wrote:
> I usually do something like this:
>
> public class Customer
> {
>
>   private IList<Order> _orders;
>
>   public Customer()
>   {
>     _orders = new List<Order>();
>   }
>
>   public IEnumerable<Order> Orders { get { return _orders; } }
>
>   public void AddOrder(Order o)
>   {
>      o.Customer = this;
>      _orders.Add(o);
>   }
>
> }
> On Tue, Jul 6, 2010 at 9:50 PM, mynkow <myn...@gmail.com> wrote:
> > Component<EntitySet<DepartmentEntity>>( x => x.Departments, m =>
> > { m.HasMany<DepartmentEntity>(
Reveal.Member<EntitySet<DepartmentEntity>>(
> > "_internalCollection" ) ).Access.Field() .KeyColumn( "DepartmentOrgId"
)
> > .ForeignKeyConstraintName( "FK_OrgDepartment" ).AsSet(); } );
>
> > This is what I did after all. But I need some advices how to manage
> > collections with NHibernate. Many people advice me to use ISet,
> > IEnumerable, IList etc. for collections and avoid custom collections. > > And may be this is a good approach. But here is the question: Should I
> > always use IEnumerable for my collections and if yes how to add new
> > Items to the collection when adding an element will result to new
> > IEnumerable collection? Can Nhibernate can keep track of the
> > collection items in this situation? I do not know. I am so confused
> > right now.
>
> > On Jul 5, 2:47 pm, Paul Batum <paul.ba...@gmail.com> wrote:
> > > Off the top of my head I would have though you could do something
like:
>
> > > Component(x => x.Departments, c =>
> > > c.HasMany<DepartmentEntity>(Reveal.Member("_internalCollection"))
> > >      .Table("DEPARTMENT")
> > >      .Cascade.SaveUpdate
> > >      .Access.Field
> > >      .KeyColumn("DepartmentOrgId")
> > >      .ForeignKey("FK_OrgDepartment")
> > > );
>
> > > My syntax might be slightly off but I thought this would work... if
not,
> > can
> > > you provide more detail on why?
>
> > > On Sun, Jul 4, 2010 at 3:35 PM, mynkow <myn...@gmail.com> wrote:
> > > > Hi, I have troubles converting this xml mapping part to fluent.
Please
> > > > help me
>
> > > > <component name="Departments"
>
> >
class="Core.Domain.Collections.EntitySet`1[Core.Domain.OrgStructure.IDepartmentEntity,BusinessWare.Core],Core">
> > > >        <set name="_internalCollection" table="`DEPARTMENT`"
> > > > cascade="save-update" access="field" generic="true" lazy="true" >
> > > >          <key column="`DepartmentOrgId`" foreign-
> > > > key="FK_OrgDepartment" />
> > > >          <one-to-many
> > > > class="Domain.Model.OrgStructure.DepartmentEntity,Domain"/>
> > > >        </set>
> > > >      </component>
>
> > > > --
> > > > You received this message because you are subscribed to the Google
> > Groups
> > > > "Fluent NHibernate" group.
> > > > To post to this group, send email to
> > fluent-nhibern...@googlegroups.com.
> > > > To unsubscribe from this group, send email to
> > > > fluent-nhibernate+unsubscr...@googlegroups.com<fluent-nhibernate%2bunsubscr...@googlegroups.com>
<fluent-nhibernate%2bunsubscr...@googlegroups.com<fluent-nhibernate%252bunsubscr...@googlegroups.com>
>
> > <fluent-nhibernate%2bunsubscr...@googlegroups.com<fluent-nhibernate%252bunsubscr...@googlegroups.com>
<fluent-nhibernate%252bunsubscr...@googlegroups.com<fluent-nhibernate%25252bunsubscr...@googlegroups.com>
>
>
> > > > .
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/fluent-nhibernate?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google
Groups
> > "Fluent NHibernate" group.
> > To post to this group, send email to
fluent-nhibern...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > fluent-nhibernate+unsubscr...@googlegroups.com<fluent-nhibernate%2bunsubscr...@googlegroups.com>
<fluent-nhibernate%2bunsubscr...@googlegroups.com<fluent-nhibernate%252bunsubscr...@googlegroups.com>
>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/fluent-nhibernate?hl=en.

--
You received this message because you are subscribed to the Google Groups
"Fluent NHibernate" group.
To post to this group, send email to fluent-nhibern...@googlegroups.com.
To unsubscribe from this group, send email to
fluent-nhibernate+unsubscr...@googlegroups.com<fluent-nhibernate%2bunsubscr...@googlegroups.com>
.
For more options, visit this group at
http://groups.google.com/group/fluent-nhibernate?hl=en.



--
You received this message because you are subscribed to the Google Groups "Fluent 
NHibernate" group.
To post to this group, send email to fluent-nhibern...@googlegroups.com.
To unsubscribe from this group, send email to 
fluent-nhibernate+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/fluent-nhibernate?hl=en.

Reply via email to