如何解决如何使用“代码优先”方法在EntityFramework核心中创建NetTopologySuite点列表
我正在使用Postgresql和PostGIS作为数据存储库来构建基于.net core,Entity Framework和Npgsql的小型汽车租赁服务,但在建模租赁摘要类中的路线时遇到了麻烦。我正在使用代码优先方法。
我尝试将其建模为NetTopologySuite.Geometries.Point的列表,但是在添加迁移并更新数据库后,查询存储库时出现以下错误。
Microsoft.EntityFrameworkCore.Query: Error: An exception occurred while iterating over the results of
a query for context type 'Trafikar.API.Models.CarContext'.
System.InvalidCastException: Can't cast database type public.geometry[] to List`1
at Npgsql.NpgsqlDataReader.GetFieldValue[T](Int32 ordinal)
at lambda_method(Closure,QueryContext,DbDataReader,ResultContext,Int32[],ResultCoordinator )
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.MoveNext()
System.InvalidCastException: Can't cast database type public.geometry[] to List`1
at Npgsql.NpgsqlDataReader.GetFieldValue[T](Int32 ordinal)
at lambda_method(Closure,ResultCoordinator )
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.MoveNext()
Exception thrown: 'System.InvalidCastException' in Microsoft.EntityFrameworkCore.Relational.dll
An exception of type 'System.InvalidCastException' occurred in Microsoft.EntityFrameworkCore.Relational.dll but was not handled in user code
Can't cast database type public.geometry[] to List`1
我的出租班
public abstract class EntityBase
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public long Id { get; protected set; }
}
public class Rental : EntityBase
{
public long CarId { get; set; }
public string UserId { get; set; }
public DateTime Start { get; set; }
public DateTime? End { get; set; }
public double Price { get; set; }
public List<Point> Route { get; set; }
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。