0

私は流暢な nHibernate で自動マッピングを使用しています。

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>()
                ))

私のオーバーライドクラスは次のようなものです:

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);
    }
}

ここで、 Reader は抽象基本クラスです。サブクラスごとに個別のオーバーライド クラスを使用すると、問題なく動作します。抽象クラスのすべてのサブクラスのオーバーライドを定義する方法はありますか?

ありがとう、
ジョニー

4

1 に答える 1

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...

于 2010-12-02T09:48:57.937 に答える