I have an Entity(EF) in DAL, which have generated by Entity Framework.
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; }
}
I've created UserDto in BLL
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; }
}
To transfer data between DAL and BLL I'm using 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; }
}
How ,in this case, to transfer navigation fields between DAL and BLL? Like this:
public virtual Department Department { get; set; }
public virtual Role Role { get; set; }
How better to do:
Remove contract(interface) and transfer User(EF) to BLL directly or advice solution to solve this issue. Is it right to remove contract(interface) with architecture point of view?
The most important purpose of creating DTOs is to lose couple your DomainModel
from your DAL DTO Model
as I get you. Then it's totally wrong to couple them again by an interface.
I advise you to use the same EF model as your DomainModel and use it in your BLL unless you have a large and complex project then it's OK to be more strict to DDD implementation by having real rich DomainModel.
In that case, you should pass your DomainModel
to your DAL and nothing else and all the mapping should be inside of your DAL. You can use then some tool like AutoMapper
or just manual mapping