Is there a way to implicitly exclude certain fields/types in some DB model in C#
's MongoDB
, while still allowing to get them explicitly? for instance, I have a Model
with two big lists:
public class Model {
public string SomeName;
public List<string> ManyManyStrings; // exclude implicitly?
public List<ComplexType> VeryBigList; // exclude implicitly?
public int SomeNumber;
public byte[] LittleArrayOfBytes_NotBigDeal;
}
And when I call IMongoCollection<Model>.Find(SomeFilter)
, I have to explicitly exclude ManyManyStrings
and VeryBigList
:
var fastModel = modelCollection.Find(SomeFilter).Project<Model>(
Builders<Model>.Projection
.Exclude(m => m.ManyManyStrings)
.Exclude(m => m.VeryBigList));
Yes, I can separate them to different types or different Collection
s and associate them via ObjectId
or so...
But the model is so "right"! they just have to be there, logically... my Model
has ManyManyStrings
and VeryBigList
, it's just so much pain to start linking between Model
s and lists of List<string> ManyManyStrings
or List<ComplexType> VeryBigList
in some other collections...
(btw, I don't think [BsonIgnore]
will help here, as it prevents explicit retrieval as well. Or am I wrong? is there a way to "bypass" it?)