Closed EdwinArends closed 6 years ago
@EdwinArends The error is coming from lazy-loading. I believe in preview1, attempting to lazy-load when the entity is not tracked was silently ignored. In preview2, it started throwing to let you know that lazy-loading wasn't happening. Couple of questions:
Note from triage: we will investigate making this a warning-as-error so it can be disabled.
Made the following changes:
Leaving this open to discuss again in triage and to get answers to questions from @EdwinArends.
In our project we are using EF Core 2.1 preview 2, in the preview 1 version we used to use a lot of Include / ThenInclude methods. In the return methods we use AutoMapper to map the database objects to a return object. We use a UnitOfWork/Repository design pattern for our backend.
We explicitly use the AsNoTracking feature for performance/memory reasons. This worked fine in preview 1, but in preview 2 we get the following exception.
Steps to reproduce
We generate a simple Document class from the SQL Server database using Scaffold-DbContext:
We use a Repository interface so the service layer can access the database:
We inject the repository in the Startup class:
In our document service class the repository is injected:
This error occurs in EF Core 2.1 preview 2, in EF Core 2.1 preview 1 this code was accepted and ran perfectly well. My question is. Is this by design and do we need to change our code? Or has this accidentally gotten broken in the preview 2 version?
Kind regards, Edwin
Further technical details
EF Core version: EF Core 2.1 preview 2 Database Provider: Microsoft.EntityFrameworkCore.SqlServer Operating system: Windows 10 professional IDE: Visual Studio 2017 15.4