在返回的地方使用OR语句

时间:2015-01-24 09:19:39

标签: c# linq

我有这个退货声明,

return taskItems.Where(s => s.DateCreated >= fromDate.SelectedDate || s.DateCreated <= toDate.SelectedDate);

这应该可行,但是Visual Studio在&#34; InitializeComponent(); &#34;,

上给了我这个例外。
 Object reference not set to an instance of an object.

这是用于将任务加载到正在使用的Datagrid中的内容,

private IEnumerable<TaskEntry> LoadTasks()
    {
        var data = GetListItems("Tasks");
        var result = XElement.Parse(data.OuterXml);
        XNamespace z = "#RowsetSchema";
        var taskItems = from r in result.Descendants(z + "row")



                        //where r.Attribute("ows_Created") 
                        //where r.Attribute("ows_Client_x0020_Issue") == null

                        select new TaskEntry 
                        {
                            ID = r.Attribute("ows_ID") != null ? r.Attribute("ows_ID").Value : string.Empty,
                            IssueID = r.Attribute("ows_Client_x0020_Issue") != null ? r.Attribute("ows_Client_x0020_Issue").Value : string.Empty,
                            Client = r.Attribute("ows_Client") != null ? r.Attribute("ows_Client").Value : string.Empty,
                            Title = r.Attribute("ows_Title") != null ? r.Attribute("ows_Title").Value : string.Empty,
                            TaskType = r.Attribute("ows_Task_x0020_Type") != null ? r.Attribute("ows_Task_x0020_Type").Value : string.Empty,
                            Priority = r.Attribute("ows_Priority") != null ? r.Attribute("ows_Priority").Value : string.Empty,
                            Status = r.Attribute("ows_Status") != null ? r.Attribute("ows_Status").Value : string.Empty,
                            AssignedTo = r.Attribute("ows_AssignedTo") != null ? r.Attribute("ows_AssignedTo").Value : string.Empty,
                            Owner = r.Attribute("ows_Owner") != null ? r.Attribute("ows_Owner").Value : string.Empty,
                            Body = r.Attribute("ows_Body") != null ? r.Attribute("ows_Body").Value : string.Empty,
                            DueDate = Convert.ToDateTime(r.Attribute("ows_DueDate").Value).Date,
                            DateCreated = Convert.ToDateTime(r.Attribute("ows_Created").Value).Date,
                            Area = r.Attribute("ows_Area") != null ? r.Attribute("ows_Area").Value : string.Empty,
                            GroupTask = r.Attribute("ows_Group_x0020_Task") != null ? r.Attribute("ows_Group_x0020_Task").Value : string.Empty,
                        };

        return taskItems.Where(s => s != null && (s.DateCreated >= fromDate.SelectedDate || s.DateCreated <= toDate.SelectedDate));
    }

1 个答案:

答案 0 :(得分:0)

您需要检查您实际设置的日期过滤器使用的值。似乎fromDate或toDate都是null或者虽然没有看到更多代码但很难说?