[英]Error thrown when trying to convert from MongoDB BsonArray to IEnumerable<Users> a collection of a POCO instances
All: 所有:
Here is the information about my development environment: 这是有关我的开发环境的信息:
MongoDB 3.0.0 MongoDB 3.0.0
MongoDB C# Driver Version 1.7.0.4714 MongoDB C#驱动程序版本1.7.0.4714
Microsoft Visual Studio Professional 2013 Microsoft Visual Studio专业版2013
.NET Framework 4.0 .NET Framework 4.0
Here is one of the POCO Classes that is used in our project: 这是我们的项目中使用的POCO类之一:
public class AppUsers
{
public Object Id { get; set; }
public int UserID { get; set; }
public int CompanyID { get; set; }
public string Username { get; set; }
public string Password { get; set; }
public int RoleID { get; set; }
public DateTime LoginTime { get; set; }
public DateTime LogoutTime { get; set; }
}
Here is a quasi-stored procedure JavaScript function that queries the MongoDB Database's AppUsers collection: 这是一个查询MongoDB数据库的AppUsers集合的准存储过程JavaScript函数:
function (userIdArg
, companyIdArg
, searchTermArg
, referenceRoleIdOfInterestArg
, startRowOfInterestArg
, displayedRowsQuantityArg
, sortColumnArg
, isAscendingArg){
var usrColl = [];
usrColl = db.getCollection('AppUsersCollection').find( { "CompanyID" : companyIdArg }).sort( { sortColumnArg : isAscendingArg } ).skip(startRowOfInterestArg).limit(displayedRowsQuantityArg).toArray();
returns usrColl;
}
Here is the Excerpt from client code that will invoke the aforementioned JavaScript code: 这是客户端代码的摘录,它将调用上述JavaScript代码:
var sysJs = DBConnection.database.GetCollection("system.js");
sysJs.Remove(Query.EQ("_id", "getUsers"));
var code = File.ReadAllText(HttpContext.Current.Server.MapPath("~/Hos/quasiStoredProceduresJS/getUsers.js"));
var codeDocument = new BsonDocument("value", new BsonJavaScript(code));
codeDocument.Add(new BsonElement("_id", "getUsers"));
sysJs.Insert(codeDocument);
BsonValue getUsers = DBConnection.database.Eval("getUsers");
BsonValue bv3 = DBConnection.database.Eval(getUsers.AsBsonJavaScript.Code, null
,
loggedInUser.CompanyID
,
searchTermArg
,
ApplicationConstants.DriverRole
,
startRowOfInterest
,
displayedRowsQuantity
,
sortColumn
,
isAscending);
IEnumerable<Users> usersOfInterestList = bv3.AsBsonArray.AsQueryable();
The aforementioned line is where I'm having trouble which gives me the following error: 上述行是我遇到麻烦的地方,它给我以下错误:
Error 90 Cannot implicitly convert type 'System.Linq.IQueryable<MongoDB.Bson.BsonValue>' to 'System.Collections.Generic.IEnumerable<Users>'. An explicit conversion exists (are you missing a cast?)
How do I implement the code so that I can easily convert BSONArray containing Users to an IEnumerable collection? 如何实现代码,以便可以轻松地将包含Users的BSONArray转换为IEnumerable集合?
Thanks in Advance. 提前致谢。
我使用BsonSerializer对JSON进行反序列化,如以下代码行所示:
IEnumerable<AppUsers> usersOfInterestList = BsonSerializer.Deserialize<List<AppUsers>>(bv3.ToJson());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.