public ColQueryable <T> Match(params Expression <Func <T, bool> >[] MatchExpr) { object ret = Gobbler.GetFilter(MatchExpr); var match = new BsonDocument("$match", BsonValue.Create(ret)); var retQr = this.Clone <T>(); retQr.Stages.Add(match); return(retQr); }
public ColQueryable <T2> Project <T2>(Expression <Func <T, T2> > Selectors) { BsonDocument ret = Gobbler.GetFields(Selectors.Body, false); var match = new BsonDocument("$project", BsonValue.Create(ret)); var retQr = this.Clone <T2>(); retQr.Stages.Add(match); return(retQr); }
private static object Gobble(Expression Expr, bool IsExpr) { if (Expr is MemberExpression) { var md = Expr as MemberExpression; return(((IsExpr)?"$":"") + md.Member.Name); } if (Expr is BinaryExpression) { var bx = Expr as BinaryExpression; var ret = new Hashtable(); ret[Gobbler.GetOp(bx.NodeType)] = new object[] { Gobble(bx.Left, true), Gobble(bx.Right, true) }; return(ret); } if (Expr is ConstantExpression) { var val = Expression.Lambda(Expr).Compile().DynamicInvoke(); return(val); } if (Expr is MethodCallExpression) { var cx = Expr as MethodCallExpression; if (cx.Method.ReflectedType == typeof(Funcs)) { if (Gobbler.MultiParamsFuncs.IndexOf(";" + cx.Method.Name.ToLower() + ";") > -1) { var ret = new Hashtable(); ret["$" + cx.Method.Name.ToLower()] = Gobbler.Gobble(cx.Arguments, true); return(ret); } else { throw new NotImplementedException(); } } else { throw new NotImplementedException(); } } throw new NotImplementedException(); }
internal static BsonDocument GetFields(Expression Expr, bool IsExpr) { BsonDocument ret = new BsonDocument(); if (Expr is NewExpression) { var nx = Expr as NewExpression; var memberIndex = 0; foreach (var x in nx.Arguments) { var retField = Gobbler.Gobble(x, IsExpr); if (retField is string) { ret.Add(new BsonElement((string)retField, 1)); } else if (retField is Hashtable) { if (x is BinaryExpression) { ret.Add(new BsonElement(nx.Members[memberIndex].Name, BsonValue.Create(retField))); } else if (x is MethodCallExpression) { var retCompile = Gobble(x, true); ret.Add(new BsonElement(nx.Members[memberIndex].Name, BsonValue.Create(retCompile))); } else { throw new NotImplementedException(); } } else { throw new NotImplementedException(); } memberIndex++; } } else { throw new NotImplementedException(); } return(ret); }