-2

I try to use LINQ to filter the data, the data is from 3rd party API (JIRA Server), and ResolutionDateis DateTime type, I guess it use Nullable, anyway, I am pretty sure the value is null, but when I use LINQ, it just not work at all. The LINQ just can't do i.ResolutionDate == null, it always said there is no item match this condition. I'm pretty sure I have the issues their ResolutionDate is null.

https://developer.atlassian.com/server/jira/platform/database-issue-fields/

var foo = datas.Where(i =>
                i.Created > date && i.Created <= date.AddDays(7) && 
i.ResolutionDate> date.AddDays(7) && i.ResolutionDate== null);
ckky1213
  • 301
  • 1
  • 11
  • What is the type of `i.ResolutionDate`? – DavidG Aug 21 '18 at 17:43
  • 2
    `i.ResolutionDate` cannot simultaneously be a date more than seven days in the future and null at the same time. –  Aug 21 '18 at 17:44
  • 2
    should it be || instead of &&? – urlreader Aug 21 '18 at 17:44
  • 1
    You're "pretty sure" that there are items with ResolutionDate that are null? Before you start wondering why LINQ doesn't work, maybe you should be completely sure. – John Wu Aug 21 '18 at 17:56
  • yes, sorry the example code is incorrect, var foo = datas.Where(i => i.Created > date && i.Created <= date.AddDays(7) && i.ResolutionDate> date.AddDays(7) || i.ResolutionDate== null); then in this case, it would become ( i.Created > date && i.Created <= date.AddDays(7) && i.ResolutionDate> date.AddDays(7)) or i.ResolutionDate== null, but what I everything in the AND also include i.ResolutionDate== null – ckky1213 Aug 23 '18 at 13:00

2 Answers2

0

You should check if the value of ResolutionDate is null OR more than seven days in the future

var foo = datas.Where(i =>
                i.Created > date && i.Created <= date.AddDays(7) && 
                (i.ResolutionDate == null || i.ResolutionDate > date.AddDays(7)));
Marcus Höglund
  • 13,944
  • 9
  • 42
  • 63
  • I want to check outstanding issue, so I want to check if the ResolutionDate is null or the ResolutionDate is after this week. – ckky1213 Aug 21 '18 at 17:50
0

You could probably coalesce those into (i.ResolutionDate?.Date > date.AddDays(7))

Ultimately, it should have some condition that will return true when you do the comparison.

Manchuwook
  • 316
  • 2
  • 13