我正在使用Entity Framework Core编写Web API(.Net Core)。
我想将我的模型放在POCO库中。但是我对地理学领域有疑问。使用EF Core,我看到“地理”字段由NetTopologySuite库管理。但是如何在POCO中做到这一点?如果我引用NetTopologySuite,则意味着也要引用EF Core。
是否可以管理POCO库中与EF Core一起使用的地理字段?
示例:
public partial class Adresses
{
public DateTimeOffset CreatedAt { get; set; }
public DateTimeOffset? UpdatedAt { get; set; }
public bool Deleted { get; set; }
public int CreatedBy_Id { get; set; }
public int? UpdatedBy_Id { get; set; }
public Point Localisation { get; set; }
}
首先,您需要在上下文中进行设置
public SpatialDbContext(DbContextOptions options) : base(options) { }
第二,您在配置中将其设置为查找NetTopologySuite。
services.AddDbContext<SpatialDbContext>(opts =>
{
opts.UseSqlServer(
"<Connection string goes here>",
x => x.UseNetTopologySuite()
);
});
然后,您现在可以将界面设置为您的位置
using GeoAPI.Geometries;
namespace YourNameSpaceHere
{
public class Adresses
{
public DateTimeOffset CreatedAt { get; set; }
public DateTimeOffset? UpdatedAt { get; set; }
public bool Deleted { get; set; }
public int CreatedBy_Id { get; set; }
public int? UpdatedBy_Id { get; set; }
public IPoint Localisation { get; set; }
}
}
供参考,请检查下面的链接:
https://www.c-sharpcorner.com/article/spatial-queries-in-entity-framework-core/
希望对您有帮助。