Skip to content

Instantly share code, notes, and snippets.

@jennings
Created February 14, 2019 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jennings/6ec263d3268eb2215a3b47cf721b328c to your computer and use it in GitHub Desktop.
Save jennings/6ec263d3268eb2215a3b47cf721b328c to your computer and use it in GitHub Desktop.
#define NONEST
void Main()
{
Database.SetInitializer<MyContext>(null);
using (var db = new MyContext())
{
var date = "20180315";
var query = from row in db.Tabl1
where SqlFunctions.DateDiff(
"dd",
row.TheDate,
date.Substring(0, 4) + "-" + date.Substring(5, 2) + "-" + date.Substring(7, 2)
) > 0
select row;
query.ToString().Dump();
}
}
public class Tabl1
{
public int Id { get; set; }
public DateTime TheDate { get; set; }
}
public class MyContext : DbContext
{
public DbSet<Tabl1> Tabl1 { get; set; }
}
SELECT
[Extent1].[Id] AS [Id],
[Extent1].[TheDate] AS [TheDate]
FROM [dbo].[Tabl1] AS [Extent1]
WHERE (DATEDIFF(dd, [Extent1].[TheDate], CASE WHEN (SUBSTRING(@p__linq__0, 0 + 1, 4) IS NULL) THEN N'' ELSE SUBSTRING(@p__linq__0, 0 + 1, 4) END + N'-' + CASE WHEN (SUBSTRING(@p__linq__1, 5 + 1, 2) IS NULL) THEN N'' ELSE SUBSTRING(@p__linq__1, 5 + 1, 2) END + N'-' + CASE WHEN (SUBSTRING(@p__linq__2, 7 + 1, 2) IS NULL) THEN N'' ELSE SUBSTRING(@p__linq__2, 7 + 1, 2) END)) > 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment