I am using Visual Studio 2019. My application is in ASP.NET Core 3.0.
I'm trying to scaffold an existing database from LocalDb using the Package Manager Console with this command:
Scaffold-DbContext "Server=(localdb)\mssqllocaldb; Database=hamdoonsoft;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Appcontext
After a while I'm getting this error:
Unable to cast object of type 'Microsoft.EntityFrameworkCore.Diagnostics.RelationalLoggingDefinitions' to type 'Microsoft.EntityFrameworkCore.SqlServer.Diagnostics.Internal.SqlServerLoggingDefinitions'.
What's causing it and how can I resolve it?
This is a known issue in EFCore Preview 4, which was targeted to be fixed in Preview 5. Having encountered this issue myself, I can confirm that updating to Preview 5, which leaves my .csproj references for EFCore looking like this:
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.0.0-preview5.19227.1" /> <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.0.0-preview5.19227.1" />
Has resolved the issue and allowed me to scaffold a DBContext.