Details
-
Bug
-
Resolution: Fixed
-
Unknown
-
2.14.0
Description
If you define a nested collection as IEnumerable<T>, then you can project out elements via Select. If you define it as T[], IList<T>, or any other collection type, LINQ3 is not able to serialize it to MQL.
using System.Collections.Generic;
|
using MongoDB.Driver;
|
using MongoDB.Driver.Linq;
|
|
|
var settings = new MongoClientSettings { LinqProvider = LinqProvider.V3 };
|
var client = new MongoClient(settings);
|
var db = client.GetDatabase("test");
|
var coll = db.GetCollection<Foo>("foo");
|
|
|
var query = coll.AsQueryable().Select(x => new { MatchingBars = x.Bars.Where(y => y.Text == "foo") });
|
Console.WriteLine(query);
|
|
|
class Foo
|
{
|
public Bar[] Bars { get; set; } // <-- IEnumerable<Bar> works, but other collection types do not
|
}
|
|
|
class Bar
|
{
|
public string Text { get; set; }
|
}
|
The code throws the following exception:
Value type of serializer is Bar[] and does not match member type System.Collections.Generic.IEnumerable`1[[Bar, csharp4047, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]. (Parameter 'serializer')
|