Hi
I’m looking for a way to Find Data of another Type like a downcast.
My Structure is:
public class BaseEntry
{
public Guid Id {get;set;}
}
public class AnotherEntry : BaseEntry
{
public String Info {get;set;}
}
public class HelpEntry : BaseEntry
{
public String Help{get;set;}
}
public class LessDataEntry : BaseEntry
{
public String Name {get;set;}
}
public class AlotOfDataEntry : LessDataEntry
{
public List<int> Data {get;set;}
}
public void Do()
{
BsonClassMap.RegisterClassMap<BaseEntry>(cm => {
cm.AutoMap();
cm.SetIsRootClass(true);
cm.AddKnownType(typeof(LessDataEntry));
cm.AddKnownType(typeof(AlotOfDataEntry));
cm.AddKnownType(typeof(AnotherEntry));
cm.AddKnownType(typeof(HelpEntry));
});
AlotOfDataEntry aode = new AlotOfDataEntry () {Name="AnyName", Data=new List<int>(){1,2,3,4,5,6,7,8,9,10}};
collection.InsertOne(aode);
// Get Data as LessDataEntry will return AlotOfDataEntris
List<LessDataEntry> list = collection.AsQueryable<LessDataEntry>().OfType<LessDataEntry>().ToList()
}
I Add Data in a Type of AlotOfDataEntry and in some cases i only need to read the LessDataEntry.
So if i try to get the Entry as LessDataEntry the return type is AlotOfDataEntry with the Data Property.
How can i get only LessOfDataEntry without the List Data.
thx
Thomas