This is apparently not so obvious. I just found a very interesting forum here
To summarize if you do this
var whereFirstOrDefault = Table<AlertType>().Where(a => a.Name.Equals(alertType.Name)).FirstOrDefault();
It is very different from this.
var firstOrDefault = table.FirstOrDefault(a=> a.Name.Equals(alertType.Name));
The first query generates this command and does not retrieve the entire table:
select * from "AlertType" where ("Name" = (?)) limit 1
However, the second request:
select * from "AlertType"
As mentioned
"SQLite.TableQuery has an extension method for 'Where' that takes a predicate."
This means that Linq will modify the sql statement accordingly.
"But SQLite.TableQuery has only FirstOrDefault, which does not accept Parameters:"
This means that if you use FirstOrDefault with a predicate, it will retrieve the entire table, but if you use it without a predicate in the table, this will change the sql statement
"If you call FirstOrDefault with a predicate (my second approach) SQLite.NET selects the entire table, and then uses LINQ To Objects to do FirstOrDefault for the collection in memory."
source share