-
Type: Bug
-
Resolution: Done
-
Priority: Minor - P4
-
Affects Version/s: 1.5
-
Component/s: None
-
None
See the discussion in mongodb-csharp:
https://groups.google.com/forum/?fromgroups#!topic/mongodb-csharp/oeYHjPB7O6Q
To reproduce:
public class C { public int Id; public int X; } collection.Insert(new C { Id = 1, X = 1 }); collection.Insert(new C { Id = 2, X = 2 }); var count = collection.AsQueryable() .Select(a => a.X) .Distinct() .Count();
The exception thrown is:
System.NotSupportedException: Distinct must be used with Select to identify the field whose distinct values are to be found. at MongoDB.Driver.Linq.SelectQuery.ExecuteDistinct(IMongoQuery query) in C:\work\rstam\mongo-csharp-driver\Driver\Linq\Translators\SelectQuery.cs:line 302 at MongoDB.Driver.Linq.SelectQuery.Execute() in C:\work\rstam\mongo-csharp-driver\Driver\Linq\Translators\SelectQuery.cs:line 137 at MongoDB.Driver.Linq.MongoQueryProvider.Execute(Expression expression) in C:\work\rstam\mongo-csharp-driver\Driver\Linq\MongoQueryProvider.cs:line 155 at MongoDB.Driver.Linq.MongoQueryProvider.Execute[TResult](Expression expression) in C:\work\rstam\mongo-csharp-driver\Driver\Linq\MongoQueryProvider.cs:line 131 at System.Linq.Queryable.Count[TSource](IQueryable`1 source) at ConsoleApplication1.Program.Main(String[] _args) in C:\Users\Robert Stam\documents\visual studio 2010\Projects\ConsoleApplication1\ConsoleApplication1\Pro gram.cs:line 39