Closed corstian closed 5 years ago
Involves testing the progress booked on #1100. FYI
We should still look in to the exception, but does it work if you add a class like this to your project?
class MyDesignTimeServices : IDesignTimeServices
{
public void ConfigureDesignTimeServices(IServiceCollection services)
=> services.AddEntityFrameworkSqlServerNetTopologySuite();
}
Adding the design time services does not change the end result. I can verify that the service has been found in the log, but the same exception still occurs.
Finding design-time services for provider 'Microsoft.EntityFrameworkCore.SqlServer'...
Using design-time services from provider 'Microsoft.EntityFrameworkCore.SqlServer'.
Finding design-time services referenced by assembly 'EFCoreSpatialBugRepro'.
No referenced design-time services were found.
Finding IDesignTimeServices implementations in assembly 'EFCoreSpatialBugRepro'...
Using design-time services from class 'MyDesignTimeServices'.
The modelbuilder for entities with spatial data, which is generated with the migrations, contain the following configuration:
b.Property<SqlBytes>("Location");
Changing this into the following (or whatever specific spatial type you're using) in all your auto-generated migration files:
b.Property<Point>("Location");
Will make it work correctly!
Thanks JW!
Note that, even with the MyDesignTimeServices
, the migrations will contain the SqlBytes
type for spatial data fields.
Yep, that's a bug. Manually changing it back to Point
should fix the issue.
Wow, for some reason I thought you were trying to dbcontext scaffold
, not database update
. The design-time services are unnecessary.
Fixed by PR #13380
I'm having this even on the latest preview 3 packages.
However, I should add that it now doesn't happen for dotnet ef migrations add
, but dotnet ef database update
instead.
Did you delete your existing migrations and re-generate them?
Nope. Why is that needed?
Migrations generated by a preview of EF Core aren't guaranteed to work with future versions. (The fix for this issue was to generate different code.)
But I came from a production state of RTM, installed preview 3 for the first time, added a Point property on my model class, and generated the migration.
In other words, the error could be happening for countless users when this package goes RTM.
installed preview 3 for the first time, added a Point property on my model class, and generated the migration.
That is exactly something not supported fully. You can create migration after installing preview package and try it out but once RTM is released, you should install RTM package and recreate migrations which were generated using preview package.
@ffMathy Could you file a new issue detailing the steps so we can investigate? This was supposed to be fixed in 2.2.0-preview3, but it looks like you're still hitting it (or something like it).
@smitpatel that is not what I am saying.
I had no preview, I came from RTM, and for the first time ever installed preview 3, added a Point, and ran a migration. Then this error came up.
That should not happen either way, because then it will happen to RTM too.
Well @bricelam wiping all my existing migrations helped, but once again, these were RTM migrations, so it'll be nasty for the users when this comes out and they use it.
I can't provide steps to reproduce, as the code is under NDA.
Remove everything else just keep below code. Especially DesignTimeBMDbContext : IDesignTimeDbContextFactory this makes poblem. Just remove it. Am using 2022 and dotnet 6
public class MyDesignTimeServices : IDesignTimeServices { public void ConfigureDesignTimeServices(IServiceCollection services) => services.AddEntityFrameworkSqlServerNetTopologySuite(); }
Applying Entity Framework Core migrations with the 2.2.0 previews (and spatial extensions) does not work.
Exception message:
Stack trace:
Edit:
After trying to update the database with verbose mode enabled we can see a bit better what's going on:
Steps to reproduce
netcoreapp2.2
to theTargetFrameworks
thingy in the project file.dotnet ef migrations add 0.1
dotnet ef database update
Please note that I have been using the 2.2.0-preview2-35148 packages as there have been problems resolving the
System.Data.SqlClient
dependency on later versions.For a minimalistic demo project showing the set up for reproducing this bug; see: https://github.com/corstian/efcore-migrations-spatial-bug-reproduction.
Migrations have been generated. Running
dotnet ef database update
should trigger said bug.Further technical details
EF Core version: 2.2.0-preview-26820-02 Database Provider: Microsoft.EntityFrameworkCore.SqlServer Operating system: Windows 10 Pro Version: 10.0.17134 Build 17134