【发布时间】:2015-04-25 05:28:57
【问题描述】:
给定以下模型
[BsonDiscriminator(RootClass = true)]
[BsonKnownTypes(typeof(Employee), typeof(Contractor)]
public class Person
{
public ObjectId Id {get;set;}
public string Name {get;set;}
}
public class Employee : Person
{
public double Salary {get;set;}
}
public class Contractor : Person
{
public double DailyRate {get;set;}
}
使用旧版驱动程序,我可以执行以下操作来获取所有承包商的列表。
var employees = database.GetCollection("people").AsQueryable<Employee>().OfType<Employee>();
目前 2.0 驱动程序不支持 AsQueryable() (应该在 2.1 中不支持),所以与此同时,我对如何构建合适的过滤器来选择所有驱动程序有点茫然集合中的承包商
var list = await collection.Find(filter).ToListAsync();
【问题讨论】:
标签: c# mongodb mongodb-.net-driver