开发者

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

开发者 https://www.devze.com 2022-12-13 08:46 出处:网络
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.

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号