-
Type: Bug
-
Resolution: Done
-
Priority: Minor - P4
-
Affects Version/s: 1.4
-
Component/s: None
-
Environment:Window 7 - 64 Bit, Visual Studio 2010
This code isn't working. The
Employee class is defined as follows for the code example:
public class Employee
{
public ObjectId id
[BsonElement("fn")]
public string FirstName { get; set; }
}
If I do the following, I get an exception on the ToList() line:
var connectionString = "mongodb://localhost/sportsstore?
slaveOk=true";
var databaseName =
MongoUrl.Create(connectionString).DatabaseName;
var server = MongoServer.Create(connectionString);
var db = server.GetDatabase(databaseName);
var eCollection = db.GetCollection<Employee>("employees");
eCollection.Drop();
eCollection.Insert(new Employee
);
var employees =
eCollection.AsQueryable<Employee>().ToList();
The exception I get is this:
System.ArgumentOutOfRangeException was unhandled
Message=Specified argument was out of the range of valid values.
Parameter name: Unable to find root IQueryable
Source=MongoDB.Driver
ParamName=Unable to find root IQueryable
StackTrace:
at
MongoDB.Driver.Linq.MongoQueryTranslator.GetDocumentType(Expression
expression) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Linq
\Translators\MongoQueryTranslator.cs:line 80
at
MongoDB.Driver.Linq.MongoQueryTranslator.Translate(MongoQueryProvider
provider, Expression expression) in C:\work\10gen\mongodb\mongo-csharp-
driver\Driver\Linq\Translators\MongoQueryTranslator.cs:line 50
at MongoDB.Driver.Linq.MongoQueryProvider.Execute(Expression
expression) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Linq
\MongoQueryProvider.cs:line 146
at MongoDB.Driver.Linq.MongoQueryable`1.GetEnumerator() in C:
\work\10gen\mongodb\mongo-csharp-driver\Driver\Linq
\MongoQueryable.cs:line 81
at System.Collections.Generic.List`1..ctor(IEnumerable`1
collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at MongoQueryTester.Program.Main(String[] args) in c:\users
\ncipollina\documents\visual studio 2010\Projects\MongoQueryTester
\MongoQueryTester\Program.cs:line 27
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly,
String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile,
Evidence assemblySecurity, String[] args)
at
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object
state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state, Boolean
ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
Now if I change the line that has ToList() to this it works:
var employees = eCollection.FindAll().AsQueryable().ToList();
- duplicates
-
CSHARP-419 AsQueryable<T>().ToList() throws "System.ArgumentOutOfRangeException was unhandled" exception
- Closed