我得到了以下代码,它从 CRM 返回一组结果,然后将其绑定到 dropDownList:
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")
}
);
但是,我需要将它变成一个方法,以便我可以调用这组结果并根据其他一些标准对返回的数据执行一些 LINQ。
我不熟悉使用 LINQ 和 'var' 的整个想法来包含结果集,因此我不知道制作该方法的类型是什么:
protected static **something** getContacts()
{
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")
}
);
return contacts;
}
应该是什么类型的?