开发者

Linq to Entities - Drill down filter (Asp.net)

I've been searching for a good way of doing multiple "where" filters on an entity collection from linq. There are lots of sites that use a filter for their searches on the side, like ebay.

The technique used is called a "drill down" filter. Now I'm trying to find the right way of implementing this technique in my 3-tier model working with Linq-to-Entities.

The technique uses the earlier used received entity collection and narrows it down with some kind of filter, but there are multiple filters which can both be applied and removed even within the same "category" of filtering.

Hope somebody finds me the right link to a tutoria开发者_开发技巧l or a method of how to use this in a proper way.


In my experience, each "filter" on the side maps to a field in the database. This makes it simple to do a filter:

var result = db.Table
                 .Where(t => t.Name.Contains(ddlName.Text))
                 .Where(t => t.Attribute1.Contains(Attribute1.Text));
                 .Where(t => t.Attribute2.Contains(Attribute2.Text));

Obviously you can substitue .Equals() where it makes sense, I've used this on several webapps with great success. This becomes a bit more trickey when the filters you want do not map directly to fields in your database, but a similar approach can be taken.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜