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())
context.Filter<Post>(x => x.Where(q => q.RoleId >= myRoleID));
var list = context.Posts.ToList();
public static void GenerateData()
using (var context = new EntityContext())
context.Roles.Add(new Role() { Name = "Administrator" });
context.Roles.Add(new Role() { Name = "HR" });
context.Roles.Add(new Role() { Name = "Media" });
context.Posts.Add(new Post() { Name = "Post_A", RoleId = 1 });
context.Posts.Add(new Post() { Name = "Post_B", RoleId = 2 });
context.Posts.Add(new Post() { Name = "Post_C", RoleId = 0 });
context.Posts.Add(new Post() { Name = "Post_D", RoleId = 0 });
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 DbSet<Role> Roles { get; set; }
public int PostId { get; set; }
public string Name { get; set; }
public int RoleId { get; set; }
public int RoleId { get; set; }
public string Name { get; set; }