我在 DAL 中有一个由实体框架生成的实体(EF)。
public partial class User : IUser
{
public Guid Id { get; set; }
[Required]
[StringLength(20)]
public string Login { get; set; }
[Required]
[StringLength(25)]
public string Password { get; set; }
[Required]
[StringLength(50)]
public string Email { get; set; }
[StringLength(30)]
public string Lastname { get; set; }
[StringLength(30)]
public string Firstname { get; set; }
[StringLength(200)]
public string Avatar { get; set; }
public Guid? DepartmentId { get; set; }
public Guid? RoleId { get; set; }
public virtual Department Department { get; set; }
public virtual Role Role { get; set; }
}
我在 BLL 中创建了 UserDto
public class UserDto : IUser
{
public Guid Id { get; set; }
public string Login { get; set; }
public string Password { get; set; }
public string Email { get; set; }
public string Lastname { get; set; }
public string Firstname { get; set; }
public string Avatar { get; set; }
public DepartmentDto Department { get; set; }
public RoleDto Role { get; set; }
public Guid? DepartmentId { get; set; }
public Guid? RoleId { get; set; }
}
要在 DAL 和 BLL 之间传输数据,我使用的是 Contract(Interface)
public interface IUser
{
Guid Id { get; set; }
string Login { get; set; }
string Password { get; set; }
string Email { get; set; }
string Lastname { get; set; }
string Firstname { get; set; }
string Avatar { get; set; }
}
在这种情况下,如何在 DAL 和 BLL 之间传输导航字段?像这样:
public virtual Department Department { get; set; }
public virtual Role Role { get; set; }
怎么做更好:
删除合约(接口)并将用户(EF)直接转移到BLL或建议解决此问题的解决方案。从架构的角度删除合约(接口)是否正确?