Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Last active November 10, 2017 01:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcomartin/493fb3d52357245f898f0da17cdfce7c to your computer and use it in GitHub Desktop.
Save dcomartin/493fb3d52357245f898f0da17cdfce7c to your computer and use it in GitHub Desktop.
public class MyDbContext : DbContext
{
public Guid TenantId { get; }
public string Connection { get; }
public DbSet<Customer> Customers { get; set; }
public MyDbContext(Guid tenantId, string connection)
{
TenantId = tenantId;
Connection = connection;
this.Filter<Customer>(x => x.Where(q => q.TenantId == TenantId));
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(Connection);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment