using System.Data.Entity;
using System.Collections.Generic;
using Z.EntityFramework.Plus;
public static void Main()
using (var context = new EntityContext())
var futureMaxPrice = context.Products.DeferredMax(x => x.Prices).FutureValue<int>();
var futureMinPrice = context.Products.DeferredMin(x => x.Prices).FutureValue<int>();
int maxPrice = futureMaxPrice.Value;
int minPrice = futureMinPrice.Value;
Console.WriteLine("Max Price: {0}", maxPrice);
Console.WriteLine("Min Price: {0}", minPrice);
public static void GenerateData()
using (var context = new EntityContext())
context.Products.Add(new Product() { Name = "Product_A", IsActive = false, Prices = 35 });
context.Products.Add(new Product() { Name = "Product_B", IsActive = true, Prices = 22 });
context.Products.Add(new Product() { Name = "Product_C", IsActive = true, Prices = 37 });
context.Products.Add(new Product() { Name = "Product_D", IsActive = true, Prices = 7 });
public class EntityContext : DbContext
public EntityContext() : base(FiddleHelper.GetConnectionStringSqlServer())
public DbSet<Product> Products { get; set; }
public int ProductId { get; set; }
public string Name { get; set; }
public bool IsActive { get; set; }
public int Prices { get; set; }