alex
alex

Reputation: 76005

How to do server side pre filtering with Entity Framework and Dynamic Data?

I use Entity Framework 4.0 and need to prefilter all queries using TennantId. I modified T4 template to add pre-filter to all ObjectSets like so and it works for "regular" part of the application.

public ObjectSet<Category> Categories
{
    get
    {
        if ((_Categories == null))
        {
            _Categories = base.CreateObjectSet<Category>("Categories");
            _Categories = _Categories.Where("it.TenantId = 10");
        }
        return _Categories;
    }
}

The problem I have is that ASP.NET Dynamic Data doesn't invoke these methods and goes directly to CreateQuery which I cannot override.

Is there any way to prefilter data in this scenario?

Upvotes: 2

Views: 776

Answers (1)

muruge
muruge

Reputation: 4133

You can set a condition for each entity in your Edm and EF will automatically append that condition in the "Where" clause of all the queries it generates.

See my answer to here that might help you.

Upvotes: 1

Related Questions