Enumerable.Range in and Expression and Entity Framework
Posted
by
eka808
on Stack Overflow
See other posts from Stack Overflow
or by eka808
Published on 2012-06-18T15:01:59Z
Indexed on
2012/06/18
15:16 UTC
Read the original article
Hit count: 195
I'm currently developping an expression method (used in linq to entity queries) who has to give me
- a daycount for a given period (start date and end date)
- decrementing this daycount if specials days are in the period.
My idea was the following :
- Generate an enumerable with all the dates (and with Enumerable.Range)
- Make a .Where on this enumerable to remove the specials dates Like a MyEnumerable.Where(a => a != "20120101")
- After that, return a MyEnumerable.Count()
I come with this code :
return (p) => Enumerable
.Range(1, 4)
.Where(a => a != 20120101)
.AsQueryable()
.Count()
I tried to cast as a list, as a queryable, both (like the example) and no way ! it doesn't work ! I always get this error :
LINQ to Entities does not recognize the method 'System.Collections.Generic.IEnumerable`1[System.Int32] Range(Int32, Int32)' method, and this method cannot be translated into a store expression.
Have you got an idea about that ? Using an enumerable is of course not mandatory, any working solutions is good ^^
Thank's by advance !
© Stack Overflow or respective owner