System.Data.Entity.Spatial replacement in ASP.NET Core

后端 未结 5 1453
自闭症患者
自闭症患者 2020-12-14 02:36

I am trying to migrate a webform from ASP.NET MVC to ASP.NET Core MVC. Currently I am trying to find a way to replace:

using System.Data.Entity.Spatial;
         


        
5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-14 03:03

    With Entity Framework Core 2.2 you can use NetTopologySuite spatial library.

    You can then do a query like:

    var nearestCity = db.Cities
        .OrderBy(c => c.Location.Distance(currentLocation))
        .FirstOrDefault();
    

    A complete exemple is available here : https://www.markopapic.com/finding-nearby-users-using-ef-core-spatial-data/

提交回复
热议问题