0

i'm using automapping with fluent nHibernate, very simply, like so:

Fluently.Configure()
            .Database(MsSqlConfiguration.MsSql2008
            .ConnectionString(c => c
                .Server("(local)\\sql2008")
                .Database("nHibernate_test")
                .TrustedConnection()))
            .Mappings(m => m.AutoMappings.Add(
                AutoMap.AssemblyOf<Domain.Airport>(cfg)
                .UseOverridesFromAssemblyOf<ReaderMappingOverride>()
                ))

my overriding classes are something like that:

public class ReaderMappingOverride : IAutoMappingOverride<Domain.Reader>
{
    public void Override(AutoMapping<Domain.Reader> mapping)
    {
        //use the reader ID as identifier of the class, instead of the ID field defined in superclass Entity
        mapping.IgnoreProperty(r => r.Id);
        mapping.Id(r => r.ReaderNumber);
    }
}

where Reader is an abstract base-class. if I use a seperate overriding classes for each sub-class it works OK. Is there any way to define the overriding for all subclasses of the abstract class?

thanks,
Jhonny

1 Answers1

0

ok, just answered my own question- my problem was that i was trying to map a heirarchy which started with the Reader class, into a single table. but auto-mapping automatically ignores all abstract classes. what i did was just add this to the configuration section:

.Mappings(m => m.AutoMappings.Add(
                AutoMap.AssemblyOf<Domain.Airport>(cfg)
                .IncludeBase<Domain.Reader>()

and this to my configuration class

public override bool IsDiscriminated(Type type)
    {
       //this line indicates that the readers heirarchy should be all in one table, instead of seperate tables for every type of reader
        bool ret = type.IsSubclassOf(typeof(Domain.Reader)) || type == typeof(Domain.Reader) ;
        return ret;
    }

(BTW, the example given in Fluent nHibernate's site uses the method "type.In(..." which does not exist in .net 3.5...)
that worked fine.
hopes this helps...