我必须在这样的深对象模型中进行查找:
p.OrganisationalUnit.Parent.Head.CurrentAllocation.Person;
Run Code Online (Sandbox Code Playgroud)
无论如何要评估这个并且如果任何链为null(organizationalunit,parent,head等)则返回null,而不必执行
if (p.org == null && p.org.Parent == null && p.org.Parent.Head . . .
Run Code Online (Sandbox Code Playgroud)
看看这篇文章.它提供了一个很好的解决方案,可以让你写出这样的东西:
p.With(x => x.OrganisationalUnit)
.With(x => x.Parent)
.With(x => x.Head)
.With(x => x.CurrentAllocation
.With(x => x.Person);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4884 次 |
最近记录: |