我想知道,我在asp.net mvc 和nhibernate 中有一个应用程序。我在 asp.net mvc 的 Views 中读到了这一点,不应该知道域,它需要使用 DTO 对象。所以,我正在尝试这样做,我找到了 AutoMapper 组件,但对于某些域对象,我不知道执行 DTOS 的正确方法。我有一个这样的域类:
public class Entity
{
public virtual int Id { get; set; }
public virtual bool Active { get; set; }
}
public class Category : Entity
{
public virtual string Name { get; set; }
public virtual IList<Product> Products { get; set; }
public Category() { }
}
public class Product : Entity
{
public virtual string Name { get; set; }
public virtual string Details { get; set; }
public virtual decimal Prince { get; set; }
public virtual int Stock { get; set; }
public virtual Category Category { get; set; }
public virtual Supplier Supplier { get; set; }
public Product() { }
}
public class Supplier : Entity
{
public virtual string Name { get; set; }
public virtual IList<Product> Products { get; set; }
public Supplier() { }
}
我想获得一些示例,说明如何执行 DTO 来查看?我需要在 DTO 中只使用字符串吗?而我的控制器,它应该获取域对象或 DTO 并将其转换为域以保存在存储库中?
非常感谢!
干杯