Is it possible to specify the name of the Index property for use in lists in the free nhibernate convention?

When matching HasMany or HasManyToMany in free nhibernate, you can specify the column name to use as a parameter for the AsList () method as follows:

HasMany(c => c.Customers)
    .AsList(c => c.Column("PositionIndex"));

I would prefer to install this using the Fluent NHibernate convention (either existing or custom), especially because by default the name "Index" is a reserved word in MSSQL.

I tried using a user agreement that implements IHasManyConvention, but the instance parameter does not seem to contain information about whether there is a list, bag or set, and also does not contain column data for the index column.

public void Apply(IOneToManyCollectionInstance instance)
{

}

Any ideas?

+5
2

, . ( ) .

IAutoMappingOverride < > , .

, Todo . . thread.

+1

-

FNH 1.2 . :

class CollectionsAreListsConvention : ICollectionConvention
{
    public void Apply(ICollectionInstance instance)
    {
        instance.AsList();
        instance.Key.Column(instance.EntityType.Name + "_id");

        var mapping = (CollectionMapping)instance.GetType()
            .GetField("mapping", BindingFlags.Instance | BindingFlags.NonPublic)
            .GetValue(instance);

        if (!mapping.HasValue(m => m.Index))
        {
            var indexmapping = new IndexMapping();

            indexmapping.AddColumn(new ColumnMapping
            {
                // for Classes with more than one collection to another Class
                Name = instance.Member.Name + "_position",
            });

            mapping.Index = indexmapping;
        }
    }
}

,

+1

All Articles