using Z.EntityFramework.Plus;
using Microsoft.EntityFrameworkCore;
using Microsoft.Data.SqlClient;
using System.Collections.Generic;
public static void Main()
using (var context = new EntityContext())
context.Database.EnsureCreated();
using (var context = new EntityContext())
context.Customers.Where(x => x.IsActive).FromCache("Customers", "IsActive").ToList();
context.Customers.Delete();
FiddleHelper.WriteTable("1 - In Cache", context.Customers.Where(x => x.IsActive).FromCache("Customers", "IsActive").ToList());
QueryCacheManager.ExpireTag("Customers");
FiddleHelper.WriteTable("2 - Not In Cache", context.Customers.Where(x => x.IsActive).FromCache("Customers", "IsActive").ToList());
public static void GenerateData()
using (var context = new EntityContext())
context.Customers.Add(new Customer() { Name ="Customer_A", IsActive = false });
context.Customers.Add(new Customer() { Name ="Customer_B", IsActive = true });
context.Customers.Add(new Customer() { Name ="Customer_C", IsActive = false });
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 Boolean IsActive { get; set; }