![]() ![]() This ensures that the Migrations get put in the usual folder ( Migrations) and this custom migration can stay in it’s own folder. I have changed the namespace manually, to match the namespace that EF Core generates for it’s migrations. Important-Notice - the eagle-eyed among you will notice that the namespace differs from what Visual Studio would generate when you created the class through the Add>New Class dialog. The Migration Attribute on the Class is the name which will appear in the table: dbo._EFMigrationsHistory - This is just a unique identifier for the custom migration. ![]() Public class ApplicationDbContext : DbContext This sample application is going to store Customers and their location (latitude and longitude). Next up, we’re going to add a simple Data Model. If not - this guide will help you get up to speed. Let’s do itįirst I’m going to assume you have Entity Framework installed in your project and you can successfully run dotnet ef from the command line and see the unicorn. I’m going to detail the process of performing Custom Migrations (with the SQL Spatial Types above) as an example use. I’m not a fan of “re-inveting the wheel”, so I investigated a pretty clean (IMO) way to perform a “Custom Migration” which creates the table with the GeoTypes. It’s clear the EF Core team have this on their roadmap, but I need this functionality now. This is great, as the other option would be to store Lat/Long as double in your db and load all your locations into memory and query them there, which is not ideal.Īlong with SQL supporting these types of queries, you get all the normal ordering, filtering goodness that SQL is so good at. I’ve been wanting to use SQL Spatial types as they allow you to perform distance calculations (nearest, furthest) as part of your SQL Query. This is midly inconvenient, however they do have this issue tracked - and are currently laying the ground work for this work to be completed (after EF Core v 2.0 is released) However there are times where EntityFramework does not support a specific scenario, as I came to find out recently.Įxample code for this post can be found here: Spatial Data TypesĬurrently, Entity Framework Core does not have “built-in” support for SQL Server Spatial Data Types. Entity Framework Core will get most people/businesses quite far with their standard “out-of-the-box” functionality. ![]() In this post I’m going to cover the steps needed when setting up Entity Framework Core Custom Migrations.Ĭustom Migrations are not always needed in an application. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |