c# - mongodb 2.0 query by discriminator -


given following model

[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;} } 

with legacy driver can following list of contractors.

var employees = database.getcollection("people").asqueryable<employee>().oftype<employee>(); 

how ever @ moment asqueryable() not supported in 2.0 driver (should out 2.1) in meantime, i'm @ bit of loss on how construct suitable filter selecting contractors collection

var list = await collection.find(filter).tolistasync(); 

relevant feature request here: https://jira.mongodb.org/browse/csharp-1194

for now, can use "is" filter.

collection.find(x => x employee).tolistasync(); 

you'll still need cast @ end employee, filtered according registered discriminator.


Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -