-
Type: Bug
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: Public Preview 1
-
None
-
Dotnet Drivers
Simple data example with parent document and enumerable child document:
{{public class TestData {
public Guid Id
[BsonIgnoreIfNull]
public IEnumerable<TestChildData>? ChildData { get; set; }
}
public class TestChildData {
public Guid Id
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{ base.OnModelCreating(modelBuilder); modelBuilder .Entity<TestData>() .ToCollection(_config.Value.CollectionName) .OwnsMany(x => x.ChildData); }}}
If ChildData is null in the database, simply trying to ToList() the {{DbSet }}results in an exception:
var data = _dbContext?.TestData.ToList();
System.InvalidCastException: Unable to cast object of type 'MongoDB.Bson.BsonNull' to type 'MongoDB.Bson.BsonArray'.
at lambda_method17(Closure, QueryContext, BsonDocument)
at MongoDB.EntityFrameworkCore.Query.QueryingEnumerable`2.Enumerator.MoveNextHelper()
at MongoDB.EntityFrameworkCore.Query.QueryingEnumerable`2.Enumerator.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
Likely related to EF-99 and EF-63. This is very basic functionality that should be supported without so many problems.