连接到 CRM 2013 时,是否有一种智能方法可以创建一个 lambda 表达式,该表达式获取 GUID 位于列表中的实体。
此代码在 Where 子句上中断并给出错误:
'where' 条件无效。实体成员正在调用无效的属性或方法。
代码:
private List<UserInformationProxy> GetContactsFromGuidList(List<Guid> contactList)
{
var result = _serviceContext.ContactSet
.Where(x=> contactList.Contains((Guid) x.ContactId)) // this line breaks
.Select(x => new UserInformationProxy()
{
FullName = x.FullName,
Id = x.ContactId
})
.Distinct()
.ToList<UserInformationProxy>();
return result;
}
// return class
public class UserInformationProxy
{
public Guid? Id { get; set; }
public string FullName { get; set; }
public string DomainName { get; set; }
}
目前我正在通过从 ContactSet 中获取所有联系人并在我的代码中使用循环整理出我想要的联系人来解决这个问题。这可行,但速度很慢,因为我需要获取所有 10000 个联系人,而不是将 40 个我真正感兴趣的 Guid 发送到 SQL 服务器。