3

Mongo-C# ドライバーを 1.6.1 から 1.8.1 に更新したところ、多くの機能が廃止されていることに気付きました。非推奨のために私が見ているエラーの1つは次のとおりです。

コンベンション プロファイルは廃止されました。IConventionsPack に置き換えてください。

問題は、IConeventionPack に関するドキュメントや使用方法がまったくないことです。小さなコード スニペットを投稿していますが、IConventionPack を使用してこれを処理する方法について誰か提案してもらえますか?

var conventions = new ConventionProfile();
           conventions.SetIgnoreIfNullConvention(new AlwaysIgnoreIfNullConvention());
           BsonClassMap.RegisterConventions(conventions, t => true);

ありがとう。

4

1 に答える 1

6

さて、IConventionPack のライブラリ提供の実装がないことが判明しました。IConventionPack の実装を手書きする必要がありました。コードサンプルは次のとおりです。

public class OpusOneConvention : IConventionPack
{
    public IEnumerable<IConvention> Conventions
    {
        get { return new List<IConvention> { new IgnoreIfNullConvention(true) }; }
    }
}

に続く:

var conventions = new OpusOneConvention();
ConventionRegistry.Register("IgnoreIfNull", conventions, t => true);

したがって、基本的に、すべての規約は IEnumerable になり、ConventionRegistry がそれらの登録を担当します。

ありがとう。

注: バージョン 1.8.1.20 では、次のように ConventionPack を使用できます。

var conventions = new ConventionPack();
conventions.Add(new IgnoreIfNullConvention(true));
ConventionRegistry.Register("IgnoreIfNull", conventions, x => true);
于 2013-05-06T17:30:15.400 に答える