【发布时间】:2021-03-19 17:53:35
【问题描述】:
我有两个模型: 用户:
using System.ComponentModel.DataAnnotations;
namespace EDiary.Models
{
public class User
{
public int Id { get; set; }
[Required(AllowEmptyStrings = false, ErrorMessage = "Podaj imię")]
[MaxLength(25, ErrorMessage = "Imię jest zbyt długie. Max. 25 znaków.")]
public string FirstName { get; set; }
[Required(AllowEmptyStrings = false, ErrorMessage = "Podaj nazwisko")]
[MaxLength(25, ErrorMessage = "Nazwisko jest zbyt długie. Max. 25 znaków.")]
public string LastName { get; set; }
[EmailAddress(ErrorMessage = "Podaj prawidłowy adres e-mail")]
public string Email { get; set; }
[MinLength(7, ErrorMessage = "Hasło musi składać się z conajmniej 7 znaków")]
public string Password { get; set; }
public Class Class { get; set; }
}
}
和类:
using System.Collections.Generic;
namespace EDiary.Models
{
public class Class
{
public int Id { get; set; }
public User Educator { get; set; }
public string ClassName { get; set; }
public ICollection<User> Users { get; set; }
}
}
当我进行添加迁移时,我收到一个错误:无法确定由“用户”类型的导航“Class.Educator”表示的关系。手动配置关系,或使用“[NotMapped]”属性或使用“OnModelCreating”中的“EntityTypeBuilder.Ignore”忽略此属性。为什么?
【问题讨论】:
标签: c# entity-framework asp.net-core .net-core entity-framework-core