using System.Data.Entity;
using System.Collections.Generic;
using Z.EntityFramework.Plus;
public static void Main()
using (var context = new EntityContext())
context.Filter<Product>(q => q.Where(x => x.CategoryId == myCategoryID));
var products = context.Products.ToList();
FiddleHelper.WriteTable(products);
public static void GenerateData()
using (var context = new EntityContext())
context.Categories.Add(new Category() { Name = "Category_A" });
context.Categories.Add(new Category() { Name = "Category_B" });
context.Products.Add(new Product() { Name = "Product_A", CategoryId = 1 });
context.Products.Add(new Product() { Name = "Product_B", CategoryId = 2 });
context.Products.Add(new Product() { Name = "Product_C", CategoryId = 1 });
public class EntityContext : DbContext
public EntityContext() : base(FiddleHelper.GetConnectionStringSqlServer())
public DbSet<Product> Products { get; set; }
public DbSet<Category> Categories { get; set; }
public int ProductId { get; set; }
public string Name { get; set; }
public int CategoryId { get; set; }
public int CategoryId { get; set; }
public string Name { get; set; }