所以我有3门课:
public class OwnerDto
{
public int Id { get; set; }
public string Name { get; set; }
public string EmailAddress { get; set; }
}
public class SitterDto
{
public int Id { get; set; }
public string Name { get; set; }
public string EmailAddress { get; set; }
}
public class ReviewDto
{
public int Id { get; set; }
public int Rating { get; set; }
//[ForeignKey("OwnerId")]
public OwnerDto Owner { get; set; }
//[ForeignKey("SitterId")]
public SitterDto Sitter { get; set; }
}
但我不知道如何做正确的模型构建器。我尝试的一切都失败了:(我正在学习,所以请耐心等待。
我最接近的尝试是这样的:
modelBuilder.Entity<ReviewDto>()
.HasOne(t => t.Owner).WithMany().HasForeignKey("OwnerId");
基本上 Owner 和 Sitter 总是 null :( 我应该保留 [ForeignKey()] 的东西还是应该使用不同的扩展方法?