Getting Started - W3Schools - EF Classic

CSharp · Console

/Program.cs

// @nuget: Z.EntityFramework.Classic

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

public class Program
{
	public static void Main()
	{
		using (var context = new EntityContext())
		{
			var list = context.Customers.Where(x => x.CustomerID == 1).ToList();
			
			FiddleHelper.WriteTable("Customers", list);
			
			context.Customers.Where(x => x.CustomerID == 1).UpdateFromQuery(x => new Customer {City = "Montreal"});
						
		}
		
		using (var context = new EntityContext())
		{
					
			var list = context.Customers.Where(x => x.City == "Montreal").ToList();
			
			FiddleHelper.WriteTable("Customers", list);
			
		}
	}

	public class EntityContext : DbContext
	{
		public EntityContext() : base(FiddleHelper.GetConnectionStringSqlServerW3Schools())
		{

		}
		
		public DbSet<Customer> Customers { get; set; }
	}
	
	
	public class Customer
	{
		public int CustomerID { get; set; }
		public string CustomerName { get; set; }
		public string City{ get; set; }
	}
}
;