public static List <T> Include <T, E>(this List <T> collection, IMongoContext context) { //IMongoCollection<> secondCollection = context.GetType().GetProperties() // .FirstOrDefault(i => i.Name == "Categories").GetValue(context); //var secondCollectionData = (IMongoCollection<T> secondCollection) foreach (var book in collection) { var navigationProp = book.GetType().GetProperties().FirstOrDefault(i => typeof(E).Name.Equals(i.Name)); var navigationPropAttr = (MongoRefAttribute)navigationProp.GetCustomAttributes(typeof(MongoRefAttribute), false).FirstOrDefault(); var value = default(E); var secondCollection = (IMongoCollection <E>)context.GetType().GetProperty(navigationPropAttr.Table).GetValue(context); var secondCollectionValue = secondCollection.AsQueryable().ToList() .FirstOrDefault(i => i.GetType().GetProperty(navigationPropAttr.Id).GetValue(i) .Equals(book.GetType().GetProperty(navigationPropAttr.RefId).GetValue(book))); value = secondCollectionValue; typeof(T).GetProperty(navigationProp.Name).SetValue(book, value); } return(collection); }