1

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?

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Any link to created issue?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.