开发者

Windows Form BindingSource to LinqToSql fails to apply the 'Filter' property

I'm building a Windows Forms application and on many of these forms I use a BindingSource that is linked to a LinqToSql object. I also have a DataGridView which uses the BindingSource. This works really nice and all the 开发者_高级运维create/edit/update work.

However when I put in a string in the Filter property like this:

VesID='ABC'

it doesn't filter. Is there a special syntax that I need to make the filter work with an object datasource?


What is the binding source's SupportsFiltering?
I bet it's false because LINQ doesn't support dynamic queries out of the box.

Why do you want dynamic queries anyway? LINQ is all about type safety and you really should use its built-in filtering with Where:

var query = db.Customers.Where(x => x.VesID == "ABC");
grid.DataSource = query;

If you really do need to specify a string filter condition (which is rarely the case), have a look at two libraries: PredicateBuilder and Dynamic LINQ.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜