EF Classic - QueryFuture - Documentation - QueryFutureValue<TResult>.Value (EF Core)

CSharp · Console

/Program.cs

// Entity Framework Classic
// Doc: https://entityframework-classic.net/query-future

// @nuget: Z.EntityFramework.Classic

using System;
using System.Linq;
using System.Data.Entity;

public class Program
{
	public static void Main()
	{
		GenerateData();

		using (var context = new EntityContext())
		{			
			// Not do Select
			var futurValue = context.Customers.DeferredCount().FutureValue();
			
			// SELECT COUNT(1) FROM Customers
			Console.WriteLine("Count Customer is : " +   futurValue.Value);			
		}
	}
		 
	public static void GenerateData()
	{
		using (var context = new EntityContext())
		{
			context.Customers.Add(new Customer() { Name = "Customer_A", Description = "Description"});
			context.Customers.Add(new Customer() { Name = "Customer_B", Description = "Description"});			
			context.Customers.Add(new Customer() { Name = "Customer_C", Description = "Description"});
			
			context.SaveChanges();	
		}
	}

	public class EntityContext : DbContext
	{		
		public EntityContext() : base(FiddleHelper.GetConnectionStringSqlServer())
		{		
		}
		
		public DbSet<Customer> Customers { get; set; }
	}
	
	public class Customer
	{
		public int CustomerID { get; set; }
		public string Name { get; set; }
		public string Description { get; set; }
	}
}
;