public static IEnumerable <T> Attach <T>(this IMongoQueryable <T> q, MongoContext ctx) where T : MongoEntity { foreach (var x in q) { yield return(ctx.Attach <T>(x)); } }