更新
即使对联系人 firstName 或 LastName 进行搜索也会导致问题:
var contacts =
(
from c in context.ContactSet
join m in context.py3_membershipSet on c.ContactId equals m.py3_Member.Id
where m.statuscode.Value == 1
&& ((c.FirstName != null && c.FirstName == searchTerm) || (c.LastName!=null && c.LastName == searchTerm) || (c.FullName != null && c.FullName == searchTerm))
orderby c.LastName
select new
{
ContactId = c.ContactId,
FirstName = c.FirstName,
LastName = c.LastName,
BranchCode = c.py3_BranchArea,
Branch = (c.FormattedValues != null && c.FormattedValues.Contains("py3_brancharea") ? c.FormattedValues["py3_brancharea"] : "N/a"),
JobTitle = c.JobTitle,
Organisation = (c.ParentCustomerId != null ? c.ParentCustomerId.Name : "N/a"),
joinedAsCode = c.py3_SOLACEMemberJoinedAs,
JoinedAs = (c.FormattedValues != null && c.FormattedValues.Contains("py3_solacememberjoinedas") ? c.FormattedValues["py3_solacememberjoinedas"] : "N/a"),
Expertise = (c.py3_SOLACEMemberAreasofExpertise != null && c.py3_SOLACEMemberAreasofExpertise.Trim() != String.Empty ? c.py3_SOLACEMemberAreasofExpertise : "N/a"),
Title = c.Salutation
}
);
哪个尖叫回来:
'py3_membership' 实体不包含 Name = 'firstname' 的属性。
我得到了以下代码,可以从在线 CRM 中获取一些信息:
var context = new XrmServiceContext();
var contacts1 =
(
from c in context.ContactSet
join m in context.py3_membershipSet on c.ContactId equals m.py3_Member.Id
where m.statuscode.Value == 1
orderby c.LastName
select new
{
ContactId = c.ContactId,
FirstName = c.FirstName,
LastName = c.LastName,
BranchCode = c.py3_BranchArea,
Branch = (c.FormattedValues != null && c.FormattedValues.Contains("py3_brancharea") ? c.FormattedValues["py3_brancharea"] : "N/a"),
JobTitle = c.JobTitle,
Organisation = (c.ParentCustomerId != null ? c.ParentCustomerId.Name : "N/a"),
joinedAsCode = c.py3_SOLACEMemberJoinedAs,
JoinedAs = (c.FormattedValues != null && c.FormattedValues.Contains("py3_solacememberjoinedas") ? c.FormattedValues["py3_solacememberjoinedas"] : "N/a"),
Expertise = (c.py3_SOLACEMemberAreasofExpertise != null && c.py3_SOLACEMemberAreasofExpertise.Trim() != String.Empty ? c.py3_SOLACEMemberAreasofExpertise : "N/a")
}
);
然后我将它作为数组绑定到数据列表,一切正常。
但是我希望能够将结果限制为从下拉列表中选择的值,并期望以下工作:
var context = new XrmServiceContext();
var contacts1 =
(
from c in context.ContactSet
join m in context.py3_membershipSet on c.ContactId equals m.py3_Member.Id
where m.statuscode.Value == 1 &&
c.FormattedValues["py3_brancharea"] == ddlBranchTags.SelectedItem.Value
orderby c.LastName
select new
{
ContactId = c.ContactId,
FirstName = c.FirstName,
LastName = c.LastName,
BranchCode = c.py3_BranchArea,
Branch = (c.FormattedValues != null && c.FormattedValues.Contains("py3_brancharea") ? c.FormattedValues["py3_brancharea"] : "N/a"),
JobTitle = c.JobTitle,
Organisation = (c.ParentCustomerId != null ? c.ParentCustomerId.Name : "N/a"),
joinedAsCode = c.py3_SOLACEMemberJoinedAs,
JoinedAs = (c.FormattedValues != null && c.FormattedValues.Contains("py3_solacememberjoinedas") ? c.FormattedValues["py3_solacememberjoinedas"] : "N/a"),
Expertise = (c.py3_SOLACEMemberAreasofExpertise != null && c.py3_SOLACEMemberAreasofExpertise.Trim() != String.Empty ? c.py3_SOLACEMemberAreasofExpertise : "N/a")
}
);
但是,这会引发以下错误:
Invalid 'where' condition. An entity member is invoking an invalid property or method.
即使我硬编码分支标签标准而不是 DDL 值,它也是一样的。我还尝试在 contacts1 集上进行选择,例如:
var results = contacts1.select(c=> c.BranchTag == ddlBranchTags.SelectedItem.Value
但这会引发同样的错误。
如果我删除 branchTag where 子句,它会按预期工作。我认为假设我已经任性地这样做是公平的,因此任何有用/建设性的指针(对于 LINQ 新手)将不胜感激。谢谢。