• This repository has been archived on 05/Apr/2019
  • Stars
    star
    192
  • Rank 202,019 (Top 4 %)
  • Language
    C#
  • License
    Apache License 2.0
  • Created over 10 years ago
  • Updated almost 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Filters implementation for Entity Framework

EntityFramework.Filters

Filters implementation for Entity Framework, on NuGet as the EntityFramework.Filters package.

Filters allow you to define a parameterized filter at configuration time. At runtime, you turn on the filter and apply parameters, and every query for that entity will include the filter.

Configuration

The FilterInterceptor must be registered with Entity Framework, either through a DbConfiguration class:

public class ExampleConfiguration : DbConfiguration
{
    public ExampleConfiguration()
    {
        AddInterceptor(new FilterInterceptor());
    }
}

Or through the OnModelCreating method:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
    DbInterception.Add(new FilterInterceptor());
}

Examples

Filters are first defined, then configured. You define the filter against a single entity:

modelBuilder.Entity<Listing>()
    .Filter("ActiveListings", c => c.Condition<ListingStatus>(
        listing => listing.Status == ListingStatus.Active));

Or against a set of entities that match a type (interface or base class):

modelBuilder.Conventions.Add(
    FilterConvention.Create<IAgencyEntity, int>("Agency", (e, agencyId) => e.AgencyId == agencyId);

Filters are then enabled and parameter values filled in on a DbContext basis:

dbContext.EnableFilter("ActiveListings");
dbContext.EnableFilter("Agency")
    .SetParameter("agencyId", _userContext.CurrentUser.AgencyId);

Filters are disabled by default, and you can disable them selectively after enabling:

dbContext.DisableFilter("ActiveListings");

The filter names must be unique, and filter parameter names are matched by the parameter name you supply to the filter definition's expression.

Common Usages

Filters are used to define a predicate that will be applied to every entity in a DbContext, without a developer needing to remember to include it for every query. Common applications include:

  • Security
  • Multi-tenancy
  • Logical data partitioning
  • Soft deletes
  • Active/inactive records

There are some limitations, however:

  • No access to context for complex joins
  • Collection properties not available

More Repositories

1

MediatR

Simple, unambitious mediator implementation in .NET
C#
10,980
star
2

Respawn

Intelligent database cleaner for integration tests
C#
2,624
star
3

ContosoUniversityDotNetCore-Pages

With Razor Pages
C#
1,291
star
4

ContosoUniversityCore

JavaScript
589
star
5

presentations

Presentations I give
HTML
431
star
6

ContosoUniversityDotNetCore

JavaScript
424
star
7

ContosoUniversity

Contoso University sample re-done the way I would build it
JavaScript
394
star
8

MediatR.Extensions.Microsoft.DependencyInjection

MediatR extensions for Microsoft.Extensions.DependencyInjection
C#
327
star
9

bulk-writer

Provides guidance for fast ETL jobs, an IDataReader implementation for SqlBulkCopy (or the MySql or Oracle equivalents) that wraps an IEnumerable, and libraries for mapping entites to table columns.
C#
240
star
10

AdventureWorksCosmos

C#
96
star
11

nsb-diagnostics-poc

C#
70
star
12

SharpSSH

Fork of SharpSSH - SharpSSH is a pure .NET implementation of the SSH2 client protocol suite. It provides an API for communication with SSH servers and can be integrated into any .NET application.
C#
64
star
13

AzureAdExample

C#
50
star
14

MongoDB.Driver.Core.Extensions.DiagnosticSources

C#
42
star
15

NServiceBus.MessageRouting

Implementations of EIP message routing patterns
C#
41
star
16

QuartzNServiceBusSample

C#
39
star
17

MongoDB.Driver.Core.Extensions.OpenTelemetry

PowerShell
34
star
18

NServiceBus.Extensions.IntegrationTesting

C#
29
star
19

MicroservicesMessagingDemo

JavaScript
26
star
20

ddd-theory-and-practice-workshop-exercises

20
star
21

NServiceBus.Extensions.Diagnostics

C#
16
star
22

NServiceBus.Extensions.Diagnostics.OpenTelemetry

PowerShell
14
star
23

contosouniversitydocker

JavaScript
13
star
24

aspnetwebstack

C#
6
star
25

NServiceBusClassExample

C#
6
star
26

AutoMapper.EFCore

Port of https://github.com/AutoMapper/AutoMapper.EF6 for EF core.
C#
6
star
27

ndcsydney2017-cicd

JavaScript
5
star
28

contosouniversitydocker-linux

JavaScript
5
star
29

AzureMessagingServices

C#
5
star
30

blogexamples

Example code from posts on http://jimmybogard.lostechies.com
JavaScript
5
star
31

DotNetMigration

JavaScript
5
star
32

Oredev2016Workshop

C#
4
star
33

contosouniversity-rest

JavaScript
3
star
34

ContinuousDeliveryExample

JavaScript
3
star
35

rtd-tutorial

Python
2
star
36

NSBPerf

C#
2
star
37

AutoMapperSample

Sample Application for showing issue with AutoMapper
C#
1
star
38

NServiceBusProfiling

C#
1
star
39

sinatra-toto

Ruby
1
star
40

GenericVarianceContainerTests

C#
1
star
41

NServiceBusClassExamples

C#
1
star
42

kcdc2017-cicd

JavaScript
1
star