0

I want to create a bindingSource that supports sorting by multiple columns and attach it to a bindingNavigator. I am using winforms and code-first EF.

I am constructing my query in the following manner

DbSet<Person> dset = DBContext.People;
string Searchstr ="Smith";
string sortby ="LastName, FirstName"
var qry = (IOrderedQueryable<Person>) dset.Where(
                            p => p.LastName.Contains(Searchstr) )
                            .OrderBy(sortby);

binding.datasource = dset.Local.ToBindingList();   // where binding has been dropped on form at design time.
binding.sort = sortby;   // this is the line that screws up the sort order

I am using the extension method documented here to achieve the multi-column order by.

4

1 回答 1

0

问题原来是我设置了 binding.sortby =sortby。由于巧妙的扩展(参见问题中的链接),在查询中使用多列 sortby 是可以的,但是将 binding.sort 设置为涉及多列的表达式不起作用如果我删除该行,代码工作正常。

于 2013-11-25T19:34:11.647 回答