views:

106

answers:

0

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.TennantId = 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?

related questions