using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
using Microsoft.Data.SqlClient;
public static void Main()
using (var context = new EntityContext())
context.Database.EnsureCreated();
context.Add(new Customer() { Name = "C# Eval Expression", CreatedDate = DateTime.Now });
context.Add(new Customer() { Name = "ZZZ Projects", CreatedDate = DateTime.Now.AddMonths(-1) });
context.BulkSaveChanges();
using (var context = new EntityContext())
var customers = context.Customers.WhereDynamic(x => "EF.Functions.DateDiffMonth(x.CreatedDate, DateTime.Now) == 0").ToList();
FiddleHelper.WriteTable("1 - ", customers);
Console.WriteLine("2 - Exception: " + ex.Message);
public class EntityContext : DbContext
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
optionsBuilder.UseSqlServer(new SqlConnection(FiddleHelper.GetConnectionStringSqlServer()));
base.OnConfiguring(optionsBuilder);
public DbSet<Customer> Customers { get; set; }
public int CustomerID { get; set; }
public string Name { get; set; }
public DateTime CreatedDate { get; set; }