【发布时间】:2021-03-21 01:03:26
【问题描述】:
在 Asp net core (3.1) Identity 中,我想在用户和 TourOperators 之间添加多对多关系。 (概念是很多用户可以关注很多旅行社)。
我有旅行社类:
public class TourOperator
{
public int Id { get; set; }
public ICollection<Follow> Follows { get; set; }
}
我已经扩展了 UserIdentity 类:
public class ApplicationUser: IdentityUser
{
public ICollection<Follow> Follow { get; set; }
}
我有关注类:
public class Follow
{
public long Id { get; set; }
public string UserId { get; set; }
public ApplicationUser ApplicationUser { get; set; }
public int TourOperatorId { get; set; }
public TourOperator TourOperator{ get; set; }
}
执行迁移后,为什么在 Follow 表中我有 4 个字段而不是 3 个? 我有以下领域:
我认为 ApplicationUserId 不能存在
【问题讨论】:
-
你需要告诉 EF
UserId是链接到ApplicationUser的关键 -
一句话:约定。
ApplicationUser->ApplicationUserId
标签: asp.net-core entity-framework-core asp.net-identity