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 futurePost = context.Posts.OrderBy(x => x.CreatedDate).Take(10).Future();
var futurePostCount = context.Posts.DeferredCount().FutureValue();
var post = futurePost.ToList();
var postCount = futurePostCount.Value;
Console.WriteLine("Future Post Count: {0}", postCount);
public static void GenerateData()
using (var context = new EntityContext())
context.Posts.Add(new Post() {Title = "Post_A", CreatedDate = DateTime.Now.AddDays(-35), ViewCount = 12});
context.Posts.Add(new Post() {Title = "Post_B", CreatedDate = DateTime.Now.AddDays(-17), ViewCount = 41});
context.Posts.Add(new Post() {Title = "Post_C", CreatedDate = DateTime.Now.AddDays(-5), ViewCount = 24});
public class EntityContext : DbContext
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
optionsBuilder.UseSqlServer(new SqlConnection(FiddleHelper.GetConnectionStringSqlServer()));
base.OnConfiguring(optionsBuilder);
public DbSet<Post> Posts { get; set; }
public int PostId { get; set; }
public string Title { get; set; }
public DateTime CreatedDate { get; set; }
public int ViewCount { get; set; }