I have a function that does a database count every minute and I would like to compile the query to do so. The table is being written to (and deleted from) by multiple sources constantly and I want to gather results on the number of unique rows in use throughout the day.
My normal linq query is:
var query =
from result in dcontext.constantly_changing_table
select result.used_transaction_id;
// I'm looking for the count of unique used_transaction_id's
Console.WriteLine((query.Distinct()).Count());
How do I turn this into a compiled query? Background. I've been doing LINQ for a week and I can write complicated join statements with it. This is day one on compiled queries and I'm a bit lost. I'm not so interested in the fact that this may (or may not ) improve performance on the query, I just want to see a compiled query that works that I can build on.