Skip to content

3.1, Regression, InMemoryDatabase: 'Nullable object must have a value.' #19425

@yahorsi

Description

@yahorsi

Hi Guys,

After migration from 2.2 to 3.1 our tests started failing. (Same code works just fine on 2.2 & the exact same data). In tests we use InMemory provider witch we instantiate following way

            var options = new DbContextOptionsBuilder<CrewPageContext>()
                .UseInMemoryDatabase("Test")
                .Options;
            var context = new DatabaseContext(options, AutoMock.Resolve<ILifetimeScope>());
            context.Database.EnsureDeleted();

And here is failing query:

        public Task<List<DutyEntityForLog>> GetForDayAsync(DateTime date, Guid personId)
        {
            var result =
                from d in Context.Duties
                join pd in Context.PersonDays on new { d.Date, d.PersonId } equals new { pd.Date, pd.PersonId } into pdJoin
                from pd in pdJoin.DefaultIfEmpty()

                join f in Context.Flights on d.FlightId equals f.Id into fJoin
                from f in fJoin.DefaultIfEmpty()

                where d.Date == date && d.PersonId == personId

                select new DutyEntityForLog
                {
                    Id = d.Id,
                    Date = d.Date,
                    ActivityId = d.ActivityId,
                    Title = d.Title,

                    FlightId = d.FlightId,

                    FlightNumber = f == null ? (int?)null : f.FlightNumber,
                    OriginRcd = f == null ? null : f.OriginRcd,
                    DestinationRcd = f == null ? null : f.DestinationRcd,
                    DepartureDateTimeUtc = f == null ? (DateTime?)null : f.DepartureDateTimeUtc,

                    DateTimeFromUtc = d.DateTimeFromUtc,
                    DateTimeFromDiffToLt = d.DateTimeFromDiffToLt,
                    DateTimeToUtc = d.DateTimeToUtc,
                    DateTimeToDiffToLt = d.DateTimeToDiffToLt,

                    BlockTimeSec = d.BlockTimeSec,
                    DutyTimeSec = d.DutyTimeSec,

                    SimulationId = d.SimulationId,
                    PositioningId = d.PositioningId,

                    VacationType = d.VacationType != null ? (VacationType)d.VacationType : (VacationType?)null
                };

            return result.ToListAsync();
        }

And the exception is following:

Message: 
    System.InvalidOperationException : Nullable object must have a value.
  Stack Trace: 
    lambda_method(Closure , ValueBuffer )
    WhereSelectEnumerableIterator`2.MoveNext()
    AsyncEnumerator.MoveNextAsync()
    Enumerator.MoveNextAsync()
    EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
    EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
...

Query fails only in some cases, I'm trying to isolate it and build small repo but it might take some time.

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions