Skip to content

Commit

Permalink
Adding docs regions to filters sample.
Browse files Browse the repository at this point in the history
  • Loading branch information
anpete committed Nov 8, 2017
1 parent 3885333 commit de8b70d
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions samples/QueryFilters/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,28 @@ private static void Main()

Console.WriteLine();
}

#region IgnoreFilters

blogs = db.Blogs
.Include(b => b.Posts)
.IgnoreQueryFilters()
.ToList();

#endregion

foreach (var blog in blogs)
{
Console.WriteLine(
$"{blog.Url.PadRight(33)} [Tenant: {db.Entry(blog).Property("TenantId").CurrentValue}]");

foreach (var post in blog.Posts)
{
Console.WriteLine($" - {post.Title.PadRight(30)} [IsDeleted: {post.IsDeleted}]");
}

Console.WriteLine();
}
}
}

Expand Down Expand Up @@ -116,6 +138,8 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
.UseLoggerFactory(new LoggerFactory().AddConsole((s, l) => l == LogLevel.Information && !s.EndsWith("Connection")));
}

#region Configuration

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Blog>().Property<string>("TenantId").HasField("_tenantId");
Expand All @@ -124,6 +148,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
modelBuilder.Entity<Blog>().HasQueryFilter(b => EF.Property<string>(b, "TenantId") == _tenantId);
modelBuilder.Entity<Post>().HasQueryFilter(p => !p.IsDeleted);
}

#endregion

public override int SaveChanges()
{
Expand All @@ -147,6 +173,7 @@ public override int SaveChanges()
}

#region Entities

public class Blog
{
private string _tenantId;
Expand All @@ -168,5 +195,6 @@ public class Post
public int BlogId { get; set; }
public Blog Blog { get; set; }
}

#endregion
}

0 comments on commit de8b70d

Please sign in to comment.