将聚合的各个部分映射到 List
假设我们有一个简单的业务对象:
class SimpleBO
{
public string Field1{get;set;}
public string Field2{get;set;}
}
此外,我们还有一个复杂的聚合,如下所示:
class ComplexBO
{
public SimpleBO SimpleBOField {get;set}
public List<SomeClass> ObjectList {get;set;}
public SomeClass Object {get;set;}
}
SomeClass 本身具有 SimpleBO 的引用:
class SomeClass
{
public SimpleBO SimpleBOField {get;set}
}
现在,在我的程序的某些部分,我想获取所有不同
的列表简单的对象在某个集合中相遇。我们大量使用自动映射器,但到目前为止我还没有成功映射它。也许 LINQ 查询是更好的选择?你会如何解决这个问题?
Let us say we have a simple business object:
class SimpleBO
{
public string Field1{get;set;}
public string Field2{get;set;}
}
Also we have a complex Aggregate like that:
class ComplexBO
{
public SimpleBO SimpleBOField {get;set}
public List<SomeClass> ObjectList {get;set;}
public SomeClass Object {get;set;}
}
SomeClass itself has a reference of SimpleBO:
class SomeClass
{
public SimpleBO SimpleBOField {get;set}
}
Now in some part of my program I want to get a list of all distinct
simple objects met inside a certain aggreggate. We are using automapper heavily but I did not manage to map it so far. May be a LINQ query is a better option? How would you solve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您拥有的是:
那么您应该只需要:
这将为您提供不同的对象引用;如果您需要不同的值对,则可以重写
Equals()
/GetHashCode()
,或者作弊:Assuming what you have is:
then you should just need:
This will give you the distinct object references; if you need distinct value pairs, then either override
Equals()
/GetHashCode()
, or cheat: