MongoDB MongoCollection <bsondocument> .AsQueryable issues </bsondocument>

时间:2013-11-11 00:07:56

标签: c# linq mongodb-.net-driver

为什么以下代码在运行时失败?

MongoCollection<BsonDocument> tempCollection = DBHelper.GetInstance().TempCollection();
IList<BsonDocument> documents = (from d in tempCollection.AsQueryable()
                                         where d["Form"].AsString == id
                                         select d).ToList();

虽然这很好用吗?

MongoCollection<BsonDocument> tempCollection = DBHelper.GetInstance().TempCollection();
IList<BsonDocument> documents = (from d in tempCollection.FindAll()
                                         where d["Form"].AsString == id
                                         select d).ToList();

“id”是我的函数类型字符串的参数,此代码为。

我得到以下运行时错误:

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) <IL 0x00028, 0x001ab> at MongoDB.Driver.Linq.Utils.BsonSerializationInfoFinder.VisitMethodCall (System.Linq.Expressions.MethodCallExpression) <IL 0x00035, 0x00133> at MongoDB.Driver.Linq.ExpressionVisitor`1<MongoDB.Bson.Serialization.BsonSerializationInfo>.Visit (System.Linq.Expressions.Expression) <0x004e8> at MongoDB.Driver.Linq.Utils.BsonSerializationInfoFinder.Visit (System.Linq.Expressions.Expression) <IL 0x00014, 0x000af> at MongoDB.Driver.Linq.Utils.BsonSerializationInfoFinder.VisitMember (System.Linq.Expressions.MemberExpression) <IL 0x00007, 0x0008c> at MongoDB.Driver.Linq.ExpressionVisitor`1<MongoDB.Bson.Serialization.BsonSerializationInfo>.Visit (System.Linq.Expressions.Expression) <0x00467> at MongoDB.Driver.Linq.Utils.BsonSerializationInfoFinder.Visit (System.Linq.Expressions.Expression) <IL 0x00014, 0x000af> at MongoDB.Driver.Linq.Utils.BsonSerializationInfoFinder.GetSerializationInfo (System.Linq.Expressions.Expression,System.Collections.Generic.Dictionary`2<System.Linq.Expressions.Expression, MongoDB.Bson.Serialization.BsonSerializationInfo>) <IL 0x00009, 0x0009e> at MongoDB.Driver.Linq.Utils.BsonSerializationInfoHelper.GetSerializationInfo (System.Linq.Expressions.Expression) <IL 0x0000e, 0x0006f> at MongoDB.Driver.Linq.PredicateTranslator.BuildComparisonQuery (System.Linq.Expressions.Expression,System.Linq.Expressions.ExpressionType,System.Linq.Expressions.ConstantExpression) <IL 0x00140, 0x005d7> at MongoDB.Driver.Linq.PredicateTranslator.BuildComparisonQuery (System.Linq.Expressions.BinaryExpression) <IL 0x0008c, 0x003f7> at MongoDB.Driver.Linq.PredicateTranslator.BuildQuery (System.Linq.Expressions.Expression) <IL 0x000e6, 0x003eb> at MongoDB.Driver.Linq.SelectQuery.BuildQuery () <IL 0x00024, 0x000f3> at MongoDB.Driver.Linq.SelectQuery.Execute () <IL 0x0005c, 0x002bb> at MongoDB.Driver.Linq.MongoQueryProvider.Execute (System.Linq.Expressions.Expression) <IL 0x00017, 0x000b8> at MongoDB.Driver.Linq.MongoQueryable`1<MongoDB.Bson.BsonDocument>.GetEnumerator () <0x0004b> at System.Collections.Generic.List`1<MongoDB.Bson.BsonDocument>.AddEnumerable (System.Collections.Generic.IEnumerable`1<MongoDB.Bson.BsonDocument>) <0x00067> at System.Collections.Generic.List`1<MongoDB.Bson.BsonDocument>..ctor (System.Collections.Generic.IEnumerable`1<MongoDB.Bson.BsonDocument>) <0x0015f> at System.Linq.Enumerable.ToList<MongoDB.Bson.BsonDocument> (System.Collections.Generic.IEnumerable`1<MongoDB.Bson.BsonDocument>) <0x00077> 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[]) <IL 0x0000e, 0x000b6> at System.Web.Mvc.ActionMethodDispatcher.Execute (System.Web.Mvc.ControllerBase,object[]) <IL 0x00008, 0x00054> at System.Web.Mvc.ReflectedActionDescriptor.Execute (System.Web.Mvc.ControllerContext,System.Collections.Generic.IDictionary`2<string, object>) <IL 0x0007a, 0x003af> at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod (System.Web.Mvc.ControllerContext,System.Web.Mvc.ActionDescriptor,System.Collections.Generic.IDictionary`2<string, object>) <IL 0x00003, 0x00067> at System.Web.Mvc.ControllerActionInvoker/<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12 () <IL 0x0002d, 0x000d0> at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter (System.Web.Mvc.IActionFilter,System.Web.Mvc.ActionExecutingContext,System.Func`1<System.Web.Mvc.ActionExecutedContext>) <IL 0x00031, 0x001ca> 

任何解释或帮助表示赞赏。 感谢

编辑: 我修改了代码以使用Find方法和MongoQuery而不是使用AsQueryable扩展。基本上是照顾好事情。

MongoCollection<BsonDocument> tempCollection = DBHelper.GetInstance().TempCollection();
IList<BsonDocument> documents = tempCollection.Find(Query.EQ("Form",id)).ToList();

0 个答案:

没有答案