We are using SQLite.NET (1.5.231) in a Xamarin project
We execute Get queries like this
var result = await db.Table<T>().Where(query).ToListAsync();
Where db is a SQLiteAsyncConnection and query is a Expression<Func<T, bool>>
If I pass something like this as query it works
(intervention.EndDate == null && intervention.StartDate == day) ||
intervention.EndDate == null && intervention.StartDate <= day && day <= DateTime.Now.Date
However I'd prefer to wrap the logic up in a function and pass it like this
public async Task<IEnumerable<Intervention>> GetAMonthsInterventionsAsync(int month, int year)
{
var interventions = await this.dataProviderService.GetAsync<Intervention>(
i => ShouldInterventionBeConsideredInMonth(month, year, i),
false);
return interventions;
}
private bool ShouldInterventionBeConsideredInMonth(int month, int year, Intervention intervention)
{
DateTime startOfMonth = new DateTime(year, month, 1).StartOfDay();
DateTime endOfMonth = new DateTime(year, month, DateTime.DaysInMonth(year, month)).EndOfDay();
bool inMonth = false;
if (intervention.StartDate <= endOfMonth && intervention.EndDate != null && intervention.EndDate >= startOfMonth)
{
// Intervention starts before the month ends AND ends after the month starts
inMonth = true;
}
else if (intervention.StartDate <= endOfMonth && intervention.EndDate == null)
{
inMonth = true;
}
if (intervention.IsDeleted)
{
inMonth = false;
}
return inMonth;
}
That fails with a
**System.NotSupportedException:** 'Cannot compile: Parameter'
This is because SQLite cannot understand GetAMonthsInterventionsAsync. How can I use this kind of abstraction with SQlite?