mirror of
https://git.lewd.wtf/PGR/ascnet
synced 2025-12-13 19:04:35 +01:00
DB for starting tutorial
This commit is contained in:
19
AscNet.Common/Database/DatabaseExtensions.cs
Normal file
19
AscNet.Common/Database/DatabaseExtensions.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System.Linq.Expressions;
|
||||
using MongoDB.Bson.Serialization;
|
||||
using MongoDB.Bson.Serialization.Options;
|
||||
|
||||
namespace AscNet.Common.Database
|
||||
{
|
||||
public static class DatabaseExtensions
|
||||
{
|
||||
public static BsonClassMap<T> SetDictionaryRepresentation<T, TMember>(this BsonClassMap<T> classMap, Expression<Func<T, TMember>> memberLambda, DictionaryRepresentation representation)
|
||||
{
|
||||
var memberMap = classMap.GetMemberMap(memberLambda);
|
||||
var serializer = memberMap.GetSerializer();
|
||||
if (serializer is IDictionaryRepresentationConfigurable dictionaryRepresentationSerializer)
|
||||
serializer = dictionaryRepresentationSerializer.WithDictionaryRepresentation(representation);
|
||||
memberMap.SetSerializer(serializer);
|
||||
return classMap;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user