Automapping to create indexes on associations

51 views
Skip to first unread message

Sergey Prokhorenko

unread,
Nov 9, 2009, 11:14:58 AM11/9/09
to Fluent NHibernate
How do I tell Automapping (using conventions?) to auto-create indexes
on n-to-n associations?

public class ProductMap : IAutoMappingOverride<Product>
{
public void Override(AutoMapping<Product> mapping)
{
mapping.HasMany(x => x.Components).Index("...")
}
}

there's no Index() available. How do I index the Components.ProductId
field?

Paul Batum

unread,
Nov 19, 2009, 2:58:18 AM11/19/09
to fluent-n...@googlegroups.com
Are you talking about one to many's or many to many's? Your code example is a one to many, and it can be done like this:


  public class ProductMap : IAutoMappingOverride<Product>
  {
     public void Override(AutoMapping<Product> mapping)
     {
         mapping.HasMany(x => x.Components)
           .KeyColumns.Add("ProductId", c => c.Index("someIndex");
     }
  }

Unfortunately the same is not true for many to many's (mapped with HasManyToMany) as we have not yet migrated them over to use the ColumnMappingCollection that the one to many relies on.

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


Sergey Prokhorenko

unread,
Nov 19, 2009, 3:25:45 AM11/19/09
to Fluent NHibernate
Hm, I only see "string name" and "params string[] names" Add method
signatures. Is it in a newer release? I can't tell the exact release
that I'm using but it's couple of months old.

On Nov 19, 9:58 am, Paul Batum <paul.ba...@gmail.com> wrote:
> Are you talking about one to many's or many to many's? Your code example is
> a one to many, and it can be done like this:
>
>   public class ProductMap : IAutoMappingOverride<Product>
>   {
>      public void Override(AutoMapping<Product> mapping)
>      {
>          mapping.HasMany(x => x.Components)
>            .KeyColumns.Add("ProductId", c => c.Index("someIndex");
>      }
>   }
>
> Unfortunately the same is not true for many to many's (mapped with
> HasManyToMany) as we have not yet migrated them over to use the
> ColumnMappingCollection that the one to many relies on.
>
> On Tue, Nov 10, 2009 at 3:14 AM, Sergey Prokhorenko <
>
> sergey.prokhore...@gmail.com> wrote:
>
> > How do I tell Automapping (using conventions?) to auto-create indexes
> > on n-to-n associations?
>
> >   public class ProductMap : IAutoMappingOverride<Product>
> >   {
> >      public void Override(AutoMapping<Product> mapping)
> >      {
> >          mapping.HasMany(x => x.Components).Index("...")
> >      }
> >   }
>
> > there's no Index() available. How do I index the Components.ProductId
> > field?
> > --~--~---------~--~----~------------~-------~--~----~
> > You received this message because you are subscribed to the Google Groups
> > "Fluent NHibernate" group.
> > To post to this group, send email to fluent-n...@googlegroups.com
> > To unsubscribe from this group, send email to
> > fluent-nhibern...@googlegroups.com<fluent-nhibernate%2Bunsu...@googlegroups.com>

Paul Batum

unread,
Nov 21, 2009, 6:56:51 AM11/21/09
to fluent-n...@googlegroups.com
Yes this was added for HasMany only a month or so ago.

--


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



Reply all
Reply to author
Forward
0 new messages