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())
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
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
optionsBuilder.UseSqlServer(new SqlConnection(FiddleHelper.GetConnectionStringSqlServer()));
base.OnConfiguring(optionsBuilder);
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; }