我正在尝试在 Entity Framework Core 2.2 中进行迁移,但我遇到了一些奇怪的错误。它应该可以工作,因为文档没有说明任何关于映射代码的内容。
这个命令:
dotnet ef 迁移添加 InitialCreate
导致此错误:
属性“Point.Boundary”属于接口类型(“IGeometry”)。如果它是导航属性,则通过将其转换为映射实体类型手动配置此属性的关系,否则使用“OnModelCreating”中的 NotMappedAttribute 或“EntityTypeBuilder.Ignore”忽略该属性。
我不明白。我有一个实体、一个上下文和所有必需的依赖项,包括 EF Core 2.2 。我该如何解决?
项目文件:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.0" />
<PackageReference Include="NetTopologySuite" Version="1.15.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.0.2105168" />
</ItemGroup>
模型文件
using System.ComponentModel.DataAnnotations;
using NetTopologySuite.Geometries;
namespace WebApplication1.Models
{
public class Item
{
public int Id { get; set; }
[Required]
public string Name { get; set; }
[Required]
public Point Location { get; set; }
}
}
上下文文件
using System;
using Microsoft.EntityFrameworkCore;
using WebApplication1.Models;
namespace WebApplication1
{
public class ItemContext : DbContext
{
public ItemContext(DbContextOptions<ItemContext> options) : base(options)
{
Console.WriteLine("Context created");
}
public DbSet<Item> Items { get; set; }
protected override void OnModelCreating(ModelBuilder builder)
{
Console.WriteLine("OnModelCreating");
}
}
}