This bit of code
var realSessionCount = _appliances.CreateQuery()
.Where(a => a.Date > DateTime.UtcNow.Subtract(TimeSpan.FromDays(7)))
.Select(a => a.ApplianceId)
.Distinct()
.Count();
throws this exception
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:\source\mongo-csharp-driver\Driver\Linq\Translators\SelectQuery.cs:line 302
at MongoDB.Driver.Linq.SelectQuery.Execute() in C:\source\mongo-csharp-driver\Driver\Linq\Translators\SelectQuery.cs:line 137
at MongoDB.Driver.Linq.MongoQueryProvider.Execute(Expression expression) in C:\source\mongo-csharp-driver\Driver\Linq\MongoQueryProvider.cs:line 146
at MongoDB.Driver.Linq.MongoQueryProvider.Execute[TResult](Expression expression) in C:\source\mongo-csharp-driver\Driver\Linq\MongoQueryProvider.cs:line 130
at System.Linq.Queryable.Count[TSource](IQueryable`1 source)
at IQ.IR.Web.API.Handlers.MetricsModule.GetActiveDisplaysCount() in C:\Dev\XQ.Service\IQ.IR.Web\API\Handlers\MetricsModule.cs:line 24
this code works as expected;
var realSessionCount = _appliances.CreateQuery()
.Where(a => a.Date > DateTime.UtcNow.Subtract(TimeSpan.FromDays(7)))
.Select(a => a.ApplianceId)
.Distinct()
.ToArray()
.Count();
I think there is a bug here but if there isn't the exception message is wrong.