Whats wrong with the below query, I am getting this error: Nullable object must have a value.
Dim subscriptionUsers = From inv In dataContext.Invoices.ToList Join u In dataContext.Users _
On inv.Subscription Equals u.Subscription _
Where inv.Id.Value = invoiceID _
And Not u.Fund.Title.Contains("AGM") _
And DirectCast(IIf(Not u.EndDate.HasValue, IIf(u.StartDate.Value <= inv.EndDate.Value, True, False), _
IIf((u.StartDate.Value >= inv.StartDate.Value And u.StartDate.Value <= inv.EndDate.Value) Or _
(u.EndDate.Value >= inv.StartDate.Value And u.EndDate.Value <= inv.EndDate.Value) Or _
(u.StartDate.Value < inv.StartDate.Value And u.EndDate.Value > inv.EndDate.Value), True, False)), Boolean) _
Group By Key = u.Fund.Title Into Group _
Select Fund = Key, UsersCount = Group.Count, Users = Group.ToList, _
SubFunds = (From a In dataContext.Allocations Where a.Fund.Title = Key Select a.Department.Title Distinct)
If I remove the u.EndDate.Value in the condition then it works fine.
Here is the stack trace:
at System.Nullable1.get_Value()
at SDBReports.InvoiceAllocationReportUserControl._Lambda$__4(VB$AnonymousType_0
2 $VB$It)
at System.Linq.Enumerable.WhereEnumerableIterator1.MoveNext()
at System.Linq.Lookup
2.Create[TSource](IEnumerable1 source, Func
2 keySelector, Func2 elementSelector, IEqualityComparer
1 comparer)
at System.Linq.GroupedEnumerable4.GetEnumerator()
at System.Linq.Enumerable.WhereSelectEnumerableIterator
2.MoveNext()
at System.Linq.SystemCore_EnumerableDebugView`1.get_Items()
p.s. I have used SPMetal to generate the entity classes on SharePoint lists.
For more clarity:
do not get confused with u.EndDate.Value and inv.EndDate.Value
here is the true part for u.EndDate.Hasvalue:
IIf((u.StartDate.Value >= inv.StartDate.Value And u.StartDate.Value <= inv.EndDate.Value) Or _
(u.EndDate.Value >= inv.StartDate.Value And u.EndDate.Value <= inv.EndDate.Value) Or _
(u.StartDate.Value < inv.StartDate.Value And u.EndDate.Value > inv.EndDate.Value), True, False)
and here is the false part
IIf(u.StartDate.Value <= inv.EndDate.Value, True, False)