Permalink
Browse files

added extra properties to QueryDump and also added Explain to termina…

…te the query.
  • Loading branch information...
1 parent b2cd06f commit 481791637931621c8bbce98e777a6f68caeb1e77 @craiggwilson committed Feb 2, 2012
View
BIN PackageRelease/FluentMongo.1.3.1.1.nupkg
Binary file not shown.
View
18 src/FluentMongo/Linq/QueryableExtensions.cs
@@ -8,6 +8,17 @@ namespace FluentMongo.Linq
{
public static class QueryableExtensions
{
+ public static IDictionary<string, string> Explain<T>(this IQueryable<T> q)
+ {
+ var explanation = new Dictionary<string, string>();
+ var mongoQueryable = q as IMongoQueryable;
+ if (mongoQueryable == null)
+ return explanation;
+
+ q.QueryDump(d => explanation = d);
+ return explanation;
+ }
+
public static IQueryable<T> QueryDump<T>(this IQueryable<T> q, Action<Dictionary<string,string>> dumpTarget)
{
var mongoQueryable = q as IMongoQueryable;
@@ -30,12 +41,19 @@ public static IQueryable<T> QueryDump<T>(this IQueryable<T> q, Action<Dictionary
if (command.Query != null)
dump.Add("query", command.Query.ToJson());
+ if(command.Fields != null && command.Fields.ElementCount > 0)
+ dump.Add("fields", command.Fields.ToJson());
if (command.MapFunction != null)
dump.Add("map", command.MapFunction.ToJson());
if (command.ReduceFunction != null)
dump.Add("reduce", command.ReduceFunction.ToJson());
if (command.Sort != null)
dump.Add("sort", command.Sort.ToJson());
+
+ dump.Add("skip", command.NumberToSkip.ToString());
+ dump.Add("limit", command.NumberToLimit.ToString());
+ dump.Add("isCount", command.IsCount.ToString());
+
dumpTarget(dump);

0 comments on commit 4817916

Please sign in to comment.