Question: I'm working on a project which would show a mobile webpage within a desktop view "dashboard". The dashboard would provide some details regarding the mobile view.

My question is if I know the width and height of the mobile phone in question, how can I setup a DIV to show how it would show in that mobile phone? I want to maintain everything exactly such as font-sizing and other css considerations.

Answer: 
So what you want is that if someone would write some Linq statement like this

```
var result = myDbcontext.myDbSet.SomeLinq(...)

```

It would internally be like

```
var result = myDbContext.myDbSet
    .Where(entity => entity.tenantId == userContext.tenantId)
    .SomeLinq(...)

```

So what you should do, is that when users think that they access `myDbContext.myDbSet`, they actually get the subset where `tenantId == userContext.tenantId`

I think the neat solution would be to create a class that exposes an IQueryable for every DbSet in your DbContext and hides the actual DbContext.

Something like this:

```
class MyOriginalDbContext : DbContext
{
    public DbSet<Student> Students {get; set;}
    public DbSet<Teacher> Teachers {get; set;}
    public DbSet<ClassRoom> ClassRooms {get; set;}
    ...
}

public MyLimitedContext : IDisposable
{
    // to be filled in constructor
    private readonly MyOriginalDbcontext dbContext = ...
    private readonly int tenantId = ...

    IQueryable<Student> Students
    {
        get
        {
            return this.dbContext.Students
                .Where(student => student.tenantId == tenantId);
        }
    }

    IQueryable<Student> Teachers
    {
        get
        {
            return this.dbContext.Teachers
                .Where(teacher => teacher.tenantId == tenantId);
        }
    }
    ...

```

Users won't notice the difference:

```
using (var dbContext = new MyLimitedContext(...))
{
     var TeachersWithTheirStudents = dbContext.Teachers
         .Join(dbContext.Student)
         .GroupBy(teacher => teacher.Id,
            ...
}

```
You can use Global Query Filters. Read more [here](https://learn.microsoft.com/en-us/ef/core/querying/filters).

> 
> Such filters are automatically applied to any LINQ queries involving
>  those Entity Types, including Entity Types referenced indirectly, such
>  as through the use of Include or direct navigation property references
> 
> 
> 

An example:

```
public class Blog
{
    private string _tenantId;

    public int BlogId { get; set; }
    public string Name { get; set; }
    public string Url { get; set; }

    public List<Post> Posts { get; set; }
}

public class Post
{
    public int PostId { get; set; }
    public string Title { get; set; }
    public string Content { get; set; }
    public bool IsDeleted { get; set; }

    public int BlogId { get; set; }
    public Blog Blog { get; set; }
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.Entity<Blog>().Property<string>("TenantId").HasField("_tenantId");

    // Configure entity filters
    modelBuilder.Entity<Blog>().HasQueryFilter(b => EF.Property<string>(b, "TenantId") == _tenantId);
    modelBuilder.Entity<Post>().HasQueryFilter(p => !p.IsDeleted);
}

```

You can even disable filter for individual LINQ query if you need:

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

```