I’m using sqlite-net-pcl package (1.9.172) and when running the android version of the .Net MAUI application, I get an unsupported exception “Cannot compile: Invoke” when passing the filter lambda to a firstordefault method as per below.
Pulling all records then apply the lambda works fine.
public async Task<T> GetRecordAsync<T>(Func<T, bool> filter) where T : IIntegerPrimaryKey, new()
{
// this works
return (await _connection.Table<T>().ToListAsync()).FirstOrDefault(x => filter(x));
// this fails
//return await _connection.Table<T>().FirstOrDefaultAsync(x => filter(x));
}
I’m calling it like this:
var instrument = await localDbService.GetRecordAsync<Instrument>(x => x.Name == configuration.InstrumentName);
I then tried the following:
var instrument = localDbService.GetInstrumentByFriendlyName(configuration.InstrumentName)
where I clearly tell the compiler what’s coming…
public async Task<Instrument> GetInstrumentByFriendlyName(string instrumentName)
{
return await _connection.Table<Instrument>().FirstOrDefaultAsync(x => x.Name == instrumentName);
}
..and it works, except now it seems I need to create a class and query specific method for my specific circumstances…is this expected behaviour?