LINQ Where is the offer with four &&

I am trying to create a LINQ query with 4 arguments in a Where clause. This is a Windows 8 App project, and I am using a SQLite database. ( SQLite implementation )

Here's the code snippet:

public List<FinancialListBoxExpenseItem> retrieveExpenseItems(int month, int year, bool isPaid, StaticResources.FrequencyEnum frequencyEnum) { List<FinancialListBoxExpenseItem> tmpList = null; connection.RunInTransaction(() => { var items = from s in connection.Table<FinancialListBoxExpenseItem>() where (s.expenseDateNextPayment.Month == month) && (s.expenseDateNextPayment.Year == year) && (s.expensePaidForCurrentPeriod == isPaid) && (s.expenseFrequencyTypeEnum == frequencyEnum) select s; tmpList = items.ToList<FinancialListBoxExpenseItem>(); }); return tmpList; } 

It throws NotSupportedAction: member access failed to compile Exception expression

I have no idea what this means and how I should fix it.

Edit: works without a where clause , so the error should be related to this, where is part of the code clause

+4
source share
3 answers

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; } 
+3
source

Probably .Month not supported by your LINQ provider. You will have to work around this, possibly creating custom columns for the month and year.

+5
source

In my application, I received a NotSupportedException when running a LINQ query, and the exception information showed

Membership Access Failed to Compile Expression

As this thread tells me, the output seems to be called by the DateTime variable referenced by the request. Outside of looking for a StackOverflow stream, such as this one, to point you in the right direction, I'm not sure how anyone should figure it out on their own, but for me, changing the way I write the request has fixed the problem.

This syntax threw a "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); }); 
0
source

Source: https://habr.com/ru/post/1448113/


All Articles