1

かなり単純な(またはそう思うでしょう!)問題があり、それが私を悩ませ始めています。

簡単なクラスのセットがあります。

基本クラス「Product」は他のクラスに継承されます。Productには文字列Discriminator列「ProductType」があり、NHが正しいサブクラスを返すことができます。

以下は私が取り組んでいるものの簡単なバージョンです。

 public class ProductMap : ClassMap<Product>
{
    public ProductMap()
    {

        Table("Product");
        Id(x => x.Id)
            .GeneratedBy.Identity();

        DiscriminateSubClassesOnColumn("ProductType");


        Map(x => x.Name)
            .Length(200);
        Map(x => x.BriefDescription)
            .Length(400);

        Map(x => x.FullDescription);

        Map(x => x.Sku);
        Map(x => x.VendorSku);

        References(x => x.Vendor, "VendorId");


    }
}

public class MotorHomeMap : SubclassMap<MotorHome>
{
    public MotorHomeMap()
    {
        DiscriminatorValue("MotorHome");

        Table("MotorHome");


        //KeyColumn("ProductId");
        Map(x => x.Berths);


    }
}

ただし、単純なSession.QueryOver.List()を実行すると、実行されるクエリは次のようになります。

SELECT this_.Id               as Id1_0_,
   this_.Name             as Name1_0_,
   this_.BriefDescription as BriefDes4_1_0_,
   this_.FullDescription  as FullDesc5_1_0_,
   this_.Sku              as Sku1_0_,
   this_.VendorSku        as VendorSku1_0_,
   this_.VendorId         as VendorId1_0_,
   this_.Berths           as Berths1_0_,
   this_.ProductType      as ProductT2_1_0_

FROM製品this_

明らかに、「Berths」はProductテーブルにはなく、「MotorHome」テーブルにあります。

私はかなり単純な何かを見逃していると確信していますが、私がここで間違っていることを一生理解することはできません。

どんな助けでも大歓迎です。

4

1 に答える 1

1

指定することによりDiscriminateSubClassesOnColumn、マッピングをサブクラスごとのテーブルではなく、クラスごとのテーブル階層になるように構成します。

サブクラスに関する流暢なマッピングドキュメント

于 2011-11-14T07:14:32.003 に答える