【问题标题】:Mapping Linq-to-Sql entities to custom domain entities将 Linq-to-Sql 实体映射到自定义域实体
【发布时间】:2009-05-19 14:03:16
【问题描述】:

如何将我的 Linq-to-Sql 生成的实体 (DTO) 映射到我的域实体?问题是我无法映射关联,因为它们不是同一类型。 DTO 使用 EntitySet 和 EntityRef,而我的域实体使用 IList 和 T。

我看过一些博文:Ian Cooper 的 architecting-linq-to-sql-applications-part-5 和 digital_ruminations linq-to-sql-poco-support em> 但它们不符合我的需要。我喜欢某种通用转换器类来处理映射。

现在我做这样的事情:

public IList<Entities.Customer> GetAll()
    {
        try
        {
            return _custConverter.Convert(base.GetEntities());
        }

但是 Convert 方法只转换基本属性而不是关联。 有什么想法可以以最好的方式做到这一点吗?

【问题讨论】:

    标签: linq-to-sql mapping dns domain-driven-design


    【解决方案1】:

    您可能想查看AutoMapper。它在开箱即用地自动映射属性方面做得很好,并支持广泛的自定义,例如自定义转换器,我认为它可以用来从你的 EntitySets 中制作列表。


    更新:

    【讨论】:

    猜你喜欢
    • 2011-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多