MongoDB C# Driver 2.1.0 - resolve reference -


i have following relationships between classes:

public class person : entity {     public string firstname { get; set; }     public string lastname { get; set; } }  public class project : entity {     public string projectname { get; set; }     public mongodbref leader { get; set; } } 

i following this tutorial resolve project leader mongodbref using following snippet. unfortunately cannot find resembles fetchdbrefas<>() method in c# 2.1.0 driver mongodb

var projectcollection = this.database.getcollection<project>("projects"); var query = p in projectcollection.asqueryable<project>()             select p;  foreach (var project in query) {     console.writeline(project.projectname);     if(project.leader != null)     {         // can't figure out since          // database.fetchdbrefas<t>(...) not available anymore     } } 

can explain me how works 2.1.0 driver?

i solved writing own extension method imongodatabase. in case else stumbles across problem, might helpful:

public static async task<t> fetchdbref<t>(this imongodatabase database, mongodbref reference) t : entity {     var filter = builders<t>.filter.eq(e => e.id, reference.id.asstring);     return await database.getcollection<t>(reference.collectionname).find(filter).firstordefaultasync(); } 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -