3

假设我的域对象可以包含一堆这样的对象:

List<Thing> Things

Thing 的定义如下:

class Thing
(
    public int ThingId { get; set; }
    public string ThingName { get; set; }
)

我的 DTO 包含

List<string> ThingIds;
List<string> ThingNames;

问题是如何使用自动映射器将事物映射到 DTO 中的“相关位”?

谢谢。

基督教

4

1 回答 1

1

通过编写自定义解析器,我猜。

这是非常不寻常的要求 - 失去 id 和 name 之间的绑定。


我想你是对的。抱歉,我仍在学习 dto/viewmodel 映射。您是否认为将域对象放在 DTO 中是可以接受的,因为为 Thing 创建 dto 没有多大意义?

不要在视图模型中混合域模型。下周你会后悔的(我肯定这样做了……)。

class Thing {
    public int ThingId { get; set; }
    public string ThingName { get; set; }
    public string UnnecessaryProp {get;set;}
}

class ThingViewModel {
    public int ThingId { get; set; }
    public string ThingName { get; set; }
}

class MyView {
    public IEnumerable<ThingViewModel> Things {get;set;}
}

在这里你可以找到更多关于视图模型的想法。

于 2010-03-15T13:30:14.930 回答