title: MongoDB MongoCollection<BsonDocument>.AsQueryable issues
body: <p>Why does the below code fail at runtime?</p>
  
  <pre><code>MongoCollection&lt;BsonDocument&gt; tempCollection = DBHelper.GetInstance().TempCollection();
  IList&lt;BsonDocument&gt; documents = (from d in tempCollection.AsQueryable()
                                           where d["Form"].AsString == id
                                           select d).ToList();
  </code></pre>
  
  <p>while this works just fine?</p>
  
  <pre><code>MongoCollection&lt;BsonDocument&gt; tempCollection = DBHelper.GetInstance().TempCollection();
  IList&lt;BsonDocument&gt; documents = (from d in tempCollection.FindAll()
                                           where d["Form"].AsString == id
                                           select d).ToList();
  </code></pre>
  
  <p>"id" is a parameter of type string to my function where this code is.</p>
  
  <p>I get the below runtime error:</p>
  
  <pre><code>System.FormatException
  Input string was not in the correct format
  
  Description: HTTP 500.Error processing request.
  
  Details: Non-web exception. Exception origin (name of application or object): mscorlib.
  Exception stack trace:
  at int.Parse (string,System.Globalization.NumberStyles,System.IFormatProvider) [0x00012] in /home/karim/.yaourt/yaourt-tmp-karim/aur-mono-git/src/mono/mcs/class/corlib
  /System/Int32.cs:639 at int.Parse (string,System.IFormatProvider) [0x00000] in /home/karim/.yaourt/yaourt-tmp-karim/aur-mono-git/src/mono/mcs/class/corlib/System/Int32.cs:205 at System.Convert.ToInt32 (string,System.IFormatProvider) [0x00008] in /home/karim/.yaourt/yaourt-tmp-karim/aur-mono-git/src/mono/mcs/class/corlib/System/Convert.cs:1135 at string.System.IConvertible.ToInt32 (System.IFormatProvider) [0x00000] in /home/karim/.yaourt/yaourt-tmp-karim/aur-mono-git/src/mono/mcs/class/corlib/System/String.cs:2482 at System.Convert.ToInt32 (object,System.IFormatProvider) [0x00008] in /home/karim/.yaourt/yaourt-tmp-karim/aur-mono-git/src/mono/mcs/class/corlib/System/Convert.cs:1173 at System.Convert.ToInt32 (object) [0x00008] in /home/karim/.yaourt/yaourt-tmp-karim/aur-mono-git/src/mono/mcs/class/corlib/System/Convert.cs:1166 at MongoDB.Driver.Linq.Utils.BsonSerializationInfoFinder.VisitGetItem (System.Linq.Expressions.MethodCallExpression) &lt;IL 0x00028, 0x001ab&gt; at MongoDB.Driver.Linq.Utils.BsonSerializationInfoFinder.VisitMethodCall (System.Linq.Expressions.MethodCallExpression) &lt;IL 0x00035, 0x00133&gt; at MongoDB.Driver.Linq.ExpressionVisitor`1&lt;MongoDB.Bson.Serialization.BsonSerializationInfo&gt;.Visit (System.Linq.Expressions.Expression) &lt;0x004e8&gt; at MongoDB.Driver.Linq.Utils.BsonSerializationInfoFinder.Visit (System.Linq.Expressions.Expression) &lt;IL 0x00014, 0x000af&gt; at MongoDB.Driver.Linq.Utils.BsonSerializationInfoFinder.VisitMember (System.Linq.Expressions.MemberExpression) &lt;IL 0x00007, 0x0008c&gt; at MongoDB.Driver.Linq.ExpressionVisitor`1&lt;MongoDB.Bson.Serialization.BsonSerializationInfo&gt;.Visit (System.Linq.Expressions.Expression) &lt;0x00467&gt; at MongoDB.Driver.Linq.Utils.BsonSerializationInfoFinder.Visit (System.Linq.Expressions.Expression) &lt;IL 0x00014, 0x000af&gt; at MongoDB.Driver.Linq.Utils.BsonSerializationInfoFinder.GetSerializationInfo (System.Linq.Expressions.Expression,System.Collections.Generic.Dictionary`2&lt;System.Linq.Expressions.Expression, MongoDB.Bson.Serialization.BsonSerializationInfo&gt;) &lt;IL 0x00009, 0x0009e&gt; at MongoDB.Driver.Linq.Utils.BsonSerializationInfoHelper.GetSerializationInfo (System.Linq.Expressions.Expression) &lt;IL 0x0000e, 0x0006f&gt; at MongoDB.Driver.Linq.PredicateTranslator.BuildComparisonQuery (System.Linq.Expressions.Expression,System.Linq.Expressions.ExpressionType,System.Linq.Expressions.ConstantExpression) &lt;IL 0x00140, 0x005d7&gt; at MongoDB.Driver.Linq.PredicateTranslator.BuildComparisonQuery (System.Linq.Expressions.BinaryExpression) &lt;IL 0x0008c, 0x003f7&gt; at MongoDB.Driver.Linq.PredicateTranslator.BuildQuery (System.Linq.Expressions.Expression) &lt;IL 0x000e6, 0x003eb&gt; at MongoDB.Driver.Linq.SelectQuery.BuildQuery () &lt;IL 0x00024, 0x000f3&gt; at MongoDB.Driver.Linq.SelectQuery.Execute () &lt;IL 0x0005c, 0x002bb&gt; at MongoDB.Driver.Linq.MongoQueryProvider.Execute (System.Linq.Expressions.Expression) &lt;IL 0x00017, 0x000b8&gt; at MongoDB.Driver.Linq.MongoQueryable`1&lt;MongoDB.Bson.BsonDocument&gt;.GetEnumerator () &lt;0x0004b&gt; at System.Collections.Generic.List`1&lt;MongoDB.Bson.BsonDocument&gt;.AddEnumerable (System.Collections.Generic.IEnumerable`1&lt;MongoDB.Bson.BsonDocument&gt;) &lt;0x00067&gt; at System.Collections.Generic.List`1&lt;MongoDB.Bson.BsonDocument&gt;..ctor (System.Collections.Generic.IEnumerable`1&lt;MongoDB.Bson.BsonDocument&gt;) &lt;0x0015f&gt; at System.Linq.Enumerable.ToList&lt;MongoDB.Bson.BsonDocument&gt; (System.Collections.Generic.IEnumerable`1&lt;MongoDB.Bson.BsonDocument&gt;) &lt;0x00077&gt; at BusinessFlowManager.Controllers.FormController.Preview (string) [0x0012b] in /home/karim/MonoDevelopProjects/BusinessFlowManager/BusinessFlowManager/Controllers/SetupControllers/FormController.cs:139 at (wrapper dynamic-method) object.lambda_method (System.Runtime.CompilerServices.Closure,System.Web.Mvc.ControllerBase,object[]) &lt;IL 0x0000e, 0x000b6&gt; at System.Web.Mvc.ActionMethodDispatcher.Execute (System.Web.Mvc.ControllerBase,object[]) &lt;IL 0x00008, 0x00054&gt; at System.Web.Mvc.ReflectedActionDescriptor.Execute (System.Web.Mvc.ControllerContext,System.Collections.Generic.IDictionary`2&lt;string, object&gt;) &lt;IL 0x0007a, 0x003af&gt; at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod (System.Web.Mvc.ControllerContext,System.Web.Mvc.ActionDescriptor,System.Collections.Generic.IDictionary`2&lt;string, object&gt;) &lt;IL 0x00003, 0x00067&gt; at System.Web.Mvc.ControllerActionInvoker/&lt;&gt;c__DisplayClass15.&lt;InvokeActionMethodWithFilters&gt;b__12 () &lt;IL 0x0002d, 0x000d0&gt; at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter (System.Web.Mvc.IActionFilter,System.Web.Mvc.ActionExecutingContext,System.Func`1&lt;System.Web.Mvc.ActionExecutedContext&gt;) &lt;IL 0x00031, 0x001ca&gt; 
  </code></pre>
  
  <p>Any explanation or assistance is appreciated.
  Thanks</p>
  
  <p>EDIT:
  I've modified the code to use Find method along with a MongoQuery instead of using the AsQueryable extension. Essentially takes care of things.</p>
  
  <pre><code>MongoCollection&lt;BsonDocument&gt; tempCollection = DBHelper.GetInstance().TempCollection();
  IList&lt;BsonDocument&gt; documents = tempCollection.Find(Query.EQ("Form",id)).ToList();
  </code></pre>