Alex M
Alex M

Reputation: 2548

NHibernate mapping by code Map collection

I'm moving from xml mapping to a code based mapping. There is a problem I'm experiencing with NHibernate Map collection.

Below is the xml mapping which perfectly works (it is a bit simplified, there is actually more properties and collections):

<class name="Company" where="IsDeleted=0" lazy="false">
    <id name="Id">
        <generator class="guid"></generator>
    </id>
            <map name="Contacts" lazy="true" cascade="all" where="IsDeleted=0">
        <key column="CompanyId"></key>
        <index column="Id" type="guid"></index>
        <one-to-many class="CompanyContact"/>
    </map>
</class>

The alternate code mapping I came up with is next:

public CompanyMap()
{
    Id(x => x.Id, mapper => mapper.Generator(Generators.Guid));
    Map(x => x.Contacts,
    m =>
    {
    m.Where(FILTER);
    m.Cascade(Cascade.All);
    m.Lazy(CollectionLazy.Lazy);
    m.Key(c => c.Column("CompanyId"));
    }, k =>
    {
    k.Element(e =>
    {
        e.Column("Id");
    });
    k.OneToMany(e => e.Class(typeof(CompanyContact)));
    });
}

The above generates next hbml for map:

<map name="Contacts" lazy="true" cascade="all" where="IsDeleted=0">
  <key column="CompanyId" />
  <map-key type="Guid" />
  <one-to-many class="CompanyContact" />
</map>

I'm obviously lacking index column here. Therefore when generating SQL nhibernate will use the DefaultIndexColumnName which is idx.

So the question is how would I set the index for map?

Update: According to hibernate documentation I should be using map-key. So to rephrase the question, how would I set the column property of map-key?

Upvotes: 1

Views: 1938

Answers (1)

Alex M
Alex M

Reputation: 2548

This is not yet implemented for NHibernate version 3.3.1. Created an issue in Jira for that.

Upvotes: 1

Related Questions