2

私は次のようなエンティティを持っています:

public class Land
{
    public virtual IDictionary<string, int> Damages { get; set; }
    // and other properties
}

次のコードで自動マッピングを使用しようとするたびに:

var sessionFactory = Fluently.Configure()
    .Database(SQLiteConfiguration.Standard.InMemory)
    .Mappings(m => m.AutoMappings.Add(AutoMap.AssemblyOf<Land>))
    .BuildSessionFactory();

次のエラーが表示されます。

{"The type or method has 2 generic parameter(s), but 1 generic argument(s) were
provided. A generic argument must be provided for each generic parameter."}

誰かが私が間違っていることを教えてもらえますか? また、これは簡単な例です。私はこの辞書以外にもたくさんの辞書を持っています。

4

3 に答える 3

8

NHibernate では不可能です。

于 2009-12-30T09:28:30.560 に答える
3

これが不可能であるという痕跡がいくつか見つかりました。最近実装された痕跡があります。

まだまだ調査中。:)


これは非常に有望に見えます(まだテストしていません)。

したがって、あなたの場合は次のようになります=>

public class LandMap : ClassMap<Land>
{
    public LandMap()
    {
        (...)

        HasMany(x => x.Damages)
            .WithTableName("Damages")
            .KeyColumnNames.Add("LandId")
            .Cascade.All()
            .AsMap<string>(
                index => index.WithColumn("DamageType").WithType<string>(),
                element => element.WithColumn("Amount").WithType<int>()
            );
    }
}

心に留めておいてください -すべきです。私はそれをテストしませんでした。

于 2009-12-23T23:09:43.683 に答える
1

理論的には自動マッピングで機能する可能性のある回避策:

public class DamagesDictionary : Dictionary<string, int>
{
}

Land.cs

public class Land
{
   public virtual DamagesDictionary Damages { get; set; }
   // and other properties
}

またはより一般的なアプローチ...

public class StringKeyedDictionary<T> : Dictionary<string, T>
{
}

Land.cs

public class Land
{
   public virtual StringKeyedDictionary<int> Damages { get; set; }
   // and other properties
}
于 2010-09-29T06:55:27.683 に答える