我有一个在 Contains 运算符上失败的 2 阶段查询连接。我得到的错误是对象引用未设置为对象的实例。我正在预先创建动态查询,并在连接中执行。
这有效: AQuery.Where("AssigneeName == \"Michael Jackson\"")
这失败了“对象引用未设置为对象的实例”:AQuery.Where("AssigneeName.Contains(\"Michael Jackson\")")
这是我的代码:
using (ReqEntitiesDataContext dc = new ReqEntitiesDataContext(SPContext.Current.Web.Url))
{
// LINQ Deferred Query Execution
var AQuery = from a in dc.Assignees select a;
if (assigneeQuery.Count > 0)
{
AQuery = from a in AQuery.Where(string.Join(" ", assigneeQuery.ToArray())) select a;
}
var RQuery = from r in dc.ReqLibrary select r;
if (requestQuery.Count > 0)
{
RQuery = from r in RQuery.Where(string.Join(" ", requestQuery.ToArray())) select r;
}
// LINQ 2 Stage Query Execution Join
var resultQuery = from a in AQuery.ToList()
join r in RQuery on a.Title equals r.RequestID
orderby r.RequestID ascending
select new RequestType
{
RequestID = r.RequestID,
ReceivedDate = r.ReceivedDate.Value,
RequestType = r.RequestType,
Assignee = a.AssigneeName,
AssigneeSection = a.AssigneeSection,
AssigneeDivision = a.AssigneeDivision,
RequestStatus = r.RequestStatus
};
CreateTableResults(resultQuery);
}