Skip to content

Include with InMemory provider does not return records when required navigation are null #9470

@stevejgordon

Description

@stevejgordon

I have a question and possible bug to report in EF Core 2.0.

In our project we have been using the InMemory provider with EF as part of our unit testing strategy. We are able to setup a clean InMemory "database" with a set of test data which we can then use to validate our query code is working as expected.

After upgrading to 2.0.0 I noticed that we had multiple test failures across the project. On investigating I found that in many cases it was that queries were returning not returning the same records as in 1.x. On investigation I noticed that it was in cases were we were not setting related entities for the navigational properties, but where the query specific Included these.

In the test case we only setup the specific entity and related entities for those elements we will be testing.

Question: Has this behaviour changed by design in 2.0.0? It now seems that if a query has Includes in it but the navigation properties are null, those records will not be returned. Previously we got the object with null navigational properties. I couldn't see any release notes or blogs posts indicating a change to this behaviour.

Possible bug: As we normally include a specific property for the foreign key and don't mark them as nullable integers, those relationships should be considered required. However, even in 2.0.0 it seems to allow the creation of an entities, without the navigational item. Is this because of the InMemory provider? I do recall reading that perhaps it did not enforce full referential integrity.

Steps to reproduce

Sample code to reproduce is available at https://github.com/stevejgordon/EfCoreIssue

Running the tests will demonstrate the differences.

Marking the foreign key as nullable does appear to then allow tests to pass in both cases.

Further technical details

EF Core version: 2.0.0
Database Provider: InMemory
Operating system: Windows 10
IDE: VS 2017 (15.3)

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions