Post Edited
Would this be possible ?
Have a query expression that is precompiled
i.e
private static Func<SmwrDataContext, int, IQueryable<Xyz>> _validXyzs =
CompiledQuery.Compile((Context context, int Id) =>
from xyz in _db.XYZs
join abc in _db.ABCs on xyz.Id equals abc.Id
where xyz.TypeId = id && xyz.Flag && abc.Flag
select xyz);
I had initially declared this within the same repository was accessing it directly, had no problems in consuming it.
public List<MyItem> GetItemsForValueRange(int xyzTypeId, double floor, double ceiling)
{
return (from xyx from _validXyzs (_db, xyzTypeId)
join num from _db.numbers xyz.ID equals num.lettersId
where
num.Value >= floor && num.Value <= ceiling
num.Flag
select new {
Name = xyz.Name,
Value = num.Value
}).ToList();
}
Later refactored the static variable into a different class as the same query was being comsumed by multiple repositories,
Declaration post refactoring was as follows (_filteredXyzs) resides in the same class as the method making it available for comsumption.
Public static IQueryable<Xyz> GetValidXyzs(Context context, int xyzTypeId)
{
return from _filteredXyzs(context, id);
}
Was consuming it post refactoring as [RepositoryName].GetValidXyzs within any particular query context, but end up with the following "System.StackOverflowException' occurred in System.Data.Linq.dll"
Xyz entity is based on the top with its availability being determined by the flags other types within master tables.
With Xyz being comsumed in many locations, i precompiled the query for better performance, just wanted to centralize this aspect to make it more maintenance friendly.
When i step through debugger static methods exits without any error, but fails during next step i.e joining and evaluation. so i'm a bit stumped on how to go about resolving this ?
I'm sorry for typos & any other incorrect inferences as my knowledge w.r.t c# and Linq is limited,
Ps: on a sidenote Linq2Action recommends a static field with a non-static method
Any help would be appreciated