LINQ Where clause with four &&

浪尽此生 提交于 2019-12-05 16:18:57

Probably .Month is not supported by your LINQ provider. You'll have to work around that, possibly by creating specialized columns for the month and the year.

This is how i solved the problem:

public List<FinancialListBoxExpenseItem> retrieveExpenseItems(int month, int year, bool isPaid, StaticResources.FrequencyEnum frequencyEnum)
{
    List<FinancialListBoxExpenseItem> tmpList = new List<FinancialListBoxExpenseItem>();

    connection.RunInTransaction(() =>
    {
        var items = from s in connection.Table<FinancialListBoxExpenseItem>()
                    let convertedDate = (DateTime)s.expenseDateNextPayment
                    where (convertedDate.Month == month)
                       && (convertedDate.Year == year)
                       && (s.expensePaidForCurrentPeriod == isPaid)
                       && (s.expenseFrequencyTypeEnum == frequencyEnum)
                    select s;
        tmpList = items.ToList();
    });

    return tmpList;
}
Robear

In my App I was getting a NotSupportedException when running a LINQ query, and the details of the exception showed

Member access failed to compile expression

As this thread let me know, the issued seemed to be caused by a DateTime variable that was being referenced in the query. Outside of finding a StackOverflow thread like this one to point you in the right direction, I'm not sure how anyone is supposed to figure that out on their own, but for me, changing the way I was writing the query fixed the problem.

This syntax was throwing the "NotSupportedException":*

IEnumerable<Foo> foos = connection.Table<Foo>().Where(foo => foo.Timestamp.Year == year);

Switching to this syntax worked just fine:

IEnumerable<Foo> foos = connection.Table<Foo>().Where(
    delegate(Foo foo)
{
    return (foo.Timestamp.Year == year);
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!