C# 当属性为[NotMapped]但另一个属性名为RelationID时,EF Core将创建FKs

C# 当属性为[NotMapped]但另一个属性名为RelationID时,EF Core将创建FKs,c#,entity-framework-core,C#,Entity Framework Core,我在DbContext public class Activity { public int ID { get; set; } // [...] More Properties [NotMapped] public Customer Customer { get; set; } public int CustomerID { get; set; } } Customer类不在数据库中,由Activity.CustomerID public class C

我在
DbContext

public class Activity
{
    public int ID { get; set; }
    // [...] More Properties
    [NotMapped]
    public Customer Customer { get; set; }
    public int CustomerID { get; set; }
}
Customer
类不在数据库中,由
Activity.CustomerID

public class Customer
{
    public int ID { get; set; }
    // [...] More Properties

    public List<Activity> Activities { get; set; }
}

谢谢大家!

如果已经手动迁移了更改,则无需迁移更改。需要进行迁移以确保当前业务状态与数据库同步。因此,如果您手动更改了DB,您已经可以使用它了,但是您的实体应该与更改相对应。从
客户
中删除
公共列表活动{get;set;}
(或者将其标记为
未映射
也会起作用)。因为您没有FK,所以您没有关系,所以EF不应该(不能)自动填充非相关实体。
The ALTER TABLE statement conflicted with the FOREIGN KEY constraint "FK_Activity_Customers_CustomerID". The conflict occurred in database "aspnet-supii-4DAAEDA2-0208-4652-AFF2-EE02C7F6A353", table "dbo.Customers", column 'ID'.