0
我有一个对象,可以有一个用户分配给它或工作组。用户可以直接分配或通过工作组分配,但对象不能同时设置。如何结合linq查询和选择不同的记录?
public class Procedure
{
.....
public Guid? AssignedToId {get;set;} //Foreign Key to AssignedTo
public Contact AssignedTo {get;set;} //Single user assignment
public Guid? AssignedWorkGroupId {get;set;} //Foreign Key to AssignedWorkGroup
public WorkGroup AssignedWorkGroup {get;set;} //Multiple user assignment
public Guid? AssignedBuisnessPartnerId {get;set;}
public BusinessPartner AssignedBuisnessPartner {get;set;}
}
我试图找出如何编写一个查询在哪里可以找到,其中用户可以直接分配或分配工作组的一部分程序。目前我有两个单独的查询,并结合我回来的名单。哪些有效,但可能效率不高。
这是我现在有:
var procedures = _procedureRepository.Get(p => p.AssignedToId == assignedId).ToList();
procedures.AddRange(_procedureRepository.Get(p => p.AssignedWorkGroup.Contacts.Select(c => c.Id).Contains(assignedId) || p.AssignedBuisnessPartner.Contacts.Select(c => c.Id).Contains(assignedId));
如果您向我们展示您的两个查询 – Aducci 2012-03-26 13:15:53
@Aducci,我会添加我的查询。 – DDiVita 2012-03-26 13:38:24