0

多対多の関係がありますが、列に特定のデータがある 1 つの行のみに制限する必要があります。

これは関係です: ここに画像の説明を入力

「Product_Type」エンティティで、「Label」フィールドをエンティティ内にあるかのようにマップする必要があります。

CultureCode=System.Threading.Thread.CurrentThread.CurrentCulture.Name.Substring(0, 2).ToUpper() の「Product_Type_Culture」データをフィルタリングして、その中に 1 行だけを表示し、「Product_Type」のラベルをマップするにはどうすればよいですか実在物 ??

私はすでにセッションeccでフィルターを作成しました...

これは私の「失礼な」間違ったマッピングです。

public class Product_TypeMap : ClassMapping<Product_Type>
    {
        public Product_TypeMap()
        {
            Id(x => x.Id, m => m.Column("Id"));

            Bag(x => x.Label, c =>
            {
                Table("Product_Type_Culture");

                c.Key(k =>
                {
                    k.Column("ProductTypeId");
                });

                c.Filter("cultureFilter", f => f.Condition("CultureCode = :cultureId"));
            }, r => r.ManyToMany(m =>
            {
                m.Class(typeof(Product_Type_Culture));
                m.Column("CultureCode");
            }));

        }
    }

ありがとうございました!

4

1 に答える 1

0

私の知る限り、 Property() または Join() にフィルターを設定することはできません

オプション1

私は言語テーブルを取り除き、テキストテーブルをマップの要素テーブルとして持っています

public class ProductType
{
    public virtual IDictionary<string, string> Labels { get; private set; }

    // used for Binding etc
    public virtual string Name
    {
        get
        {
            string label;
            var currentlanguage = Thread.CurrentThread.CurrentUICulture;     // eg en-US
            if (!map.TryGetValue(currentlanguage.Name, out label) &&        // en-US
                !map.TryGetValue(currentlanguage.Parent.Name, out label))   // en
            {
                label = "fallback name";
            }
            return label;
        }
        set { Names[Thread.CurrentThread.CurrentUICulture.Name] = value; }
    }
}

次の FNH マッピングを使用します (MbC に変換)

public ProductTypeMap()
{
    [...]
    HasMany(pt => pt.Labels)
        .Table("Texts")
        .KeyColumn("ProductTypeId")
        .AsMap("CultureCode")
        .Element("Label")
        .Not.LazyLoad()
}

長所: 柔軟 短所: 必要以上のデータが取得される可能性があり、ラベルに対してクエリを実行できない

オプション 2

カルチャ名をラベルテーブルに移動し、マッピングで初期化された式を使用します

public ProductTypeMapping()
{
    Property(pt => pt.Label, o => o.Formula("CultureCode = " + Thread.CurrentThread.CurrentUICulture.Name));
}

利点: 関連するデータのみをフェッチする 欠点: 実行時にカルチャを変更できない、ラベルを更新できない

オプション 3

1 つをフィ​​ルタと組み合わせて、フェッチされるデータを減らします

public ProductTypeMap()
{
    HasMany(pt => pt.Labels)
        .Table("Texts")
        .KeyColumn("ProductTypeId")
        .AsMap("CultureCode")
        .Element("Label")
        .ApplyFilter("cultureFilter", "CultureCode = :cultureName or CultureCode = :parentCultureName")
        .Not.LazyLoad();
}
于 2012-07-05T06:56:55.117 に答える