I have this WdUser
class inherited from SysModelBase
:
[Serializable]
public class WdUser : SysDomainModelBase, IWdUser
{
[Display(Name = "UserName")]
[MaxLength(25)]
[Required]
public string UserName { get; set; }
[Required]
[Index(IsUnique = true)]
[MaxLength(25)]
[Display(Name = "LoginName ")]
public string LoginName { get; set; }
[Display(Name = "Password ")]
[MaxLength(50)]
[Required]
[DataType(DataType.Password)]
public string Password { get; set; }
[Display(Name = "Email 地址")]
[DataType(DataType.EmailAddress)]
[MaxLength(50)]
public string Email { get; set; }
[Display(Name = "Telephone ")]
[DataType(DataType.PhoneNumber)]
[MaxLength(15)]
public string Telephone { get; set; }
[Display(Name = "LastLoginDateTime ")]
[DataType(DataType.DateTime)]
public DateTime LastLoginDateTime { get; set; }
[Required]
[Display(Name = "UserStatus ")]
public UserStatus Status { get; set; }
[Display(Name = "Roles ")]
public List<WdRole> Roles { get; set; }
public bool IsInRole(string role) => Roles.Any(item => item.RoleName == role);
[NotMapped]
public IIdentity Identity { get; set; }
}
which the SysModelBase
is like
[Serializable]
public class SysModelBase : ModelBase, ISysModel
{
[JsonIgnore]
[DataType(DataType.DateTime)]
public DateTime CreateDateTime { get; set; }
[JsonIgnore]
public WdUser CreateUser { get; set; }
[JsonIgnore]
[DataType(DataType.DateTime)]
public DateTime LastUpdateDateTime { get; set; }
[JsonIgnore]
public WdUser LastUpdateUser { get; set; }
[JsonIgnore]
public bool IsDeleted { get; set; }
public bool IsEnabled { get; set; }
}
When I run this code, I get an error:
Unable to determine the principal end of an association between the types 'SHWDTech.Platform.Model.Model.WdUser' and 'SHWDTech.Platform.Model.Model.WdUser'. The principal end of this association must be explicitly configured using either the relationship fluent API or data annotations.
How should I set the relationship with WdUser
class?
What I don't know is how to set the primary key from same table to other fields as foreign key.