Best to describe this in code…
I have this
public class A<T>
{
public static class Queries
{
public static Func<DataContext, int, T>Get =
CompiledQuery.Compile<DataContext, int, T>(
(DataContextdb, int i) => (from t in db.GetTable<T>()
where t.ID == i
select t).SingleOrDefault());
}
}
Can I create a new class and query, like this…
public class B<T>:A<t>
{
public static class BQueries
{
public static Func<DataContext, int, T> Get =
CompiledQuery.Compile<DataContext, int, T>(
(DataContext db, int id) => (from t in A.Queries.Get(db, id)
where !t.Item.Deleted
select t).SingleOrDefault());
}
public abstract TrackingItem Item;
}
All I want to do is compile a new query based on the original that adds a couple constraints. This is in lieu of executing two queries
It would work if
A.Queries.Get(...)returned anIQueryable<>, but as written your code returns aT. However, if you removeSingleOrDefault()it should work fine.Update: For good measure, this code should work:
The queries won’t actually execute until you call an immediate operator like
SingleOrDefault():