There is an entry in the database of the application that I am using with the Date field. In many places in the code, we need to translate this into a fiscal year to group, select and filter. So, here are some examples of what the query might look like:
var query = from r in DB.records let fy = r.Date.Month >= 10 ? r.Year + 1 : r.Year where fy = 2010 select r;
Now I know that I can write an expression method to use the same filter, but what if I want to use it to select and group? I do not want to write the second line again and again in all queries. It would be nice to just be able to:
var query = from r in DB.records let fy = r.Date.GetFY() where fy = 2010 group r by fy into g select g.Count();
Thus, different clients may have different definitions of FY, etc., and they will all be defined in the same place. Is there any way to do this? Writing a normal GetFY method simply raises a โCan not translate to SQLโ exception (or whatever it is). Obviously this can be translated into SQL at some level, I just donโt know if LINQ to SQL can be easily recreated to reuse.
Thanks in advance.
source share