c# - Convert SQL to LINQ with date -


i trying convert below sql command linq confused possibility convert same ouput.

select *    [a].[dbo].[sometable]   lossdate >= dateadd(m, datediff(m, 0, getdate()) - 1, 0)    , lossdate < dateadd(m, datediff(m, 0, getdate()), 0) 

thanks

the sqlfunctions class has methods translate sql server functions when used in query. (if using .net 3.5 use this version bundled entity framework instead)

your query directly translated to

db.sometable.where(x => x.lossdate >= sqlfunctions.dateadd("m", sqlfunctions.datediff("m", "0", sqlfunctions.getdate()) - 1, 0) &&                          x.lossdate < sqlfunctions.dateadd("m", sqlfunctions.datediff("m", "0", sqlfunctions.getdate()), 0)); 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -