扩展IEnumerable返回BindingList [英] Extending IEnumerable to Return BindingList
问题描述
在堆栈溢出的上一个问题中,我遇到了一个将EF查询返回给DataGridView的问题。当然我会遇到一个问题。但是,我添加了一个扩展方法,仍然让我困惑,因为它不工作。这似乎应该是,但由于某种原因,它不是。
In a previous question on Stack Overflow, I had run into an issue with returning an EF query to the DataGridView. Of course I'd run into an issue. However, I added an extension method that still has me baffled since it isn't working. It seems like it should, but for some reason it's not.
public static class BindingListEntityExtension
{
public static BindingList<T> ToBindingList<T>(this IEnumerable<T> entities)
{
BindingList<T> rtn = new BindingList<T>();
foreach (T obj in entities)
{
rtn.Add(obj);
}
return rtn;
}
}
任何想法发生了什么?我的实现是这样的:
Any ideas what's going on? My implementation is like so:
MyEntities context = new MyEntities();
tempDataGridView.DataSource = context.Employees.ToBindingList();
推荐答案
正如Ecyrb在上一篇文章中所提到的,BindingList不排序。我确实使用建议的网站/ 来列出我的列表。多谢你们!我的扩展程序现在正在工作。
Got it. As Ecyrb had suggested in a previous post, the BindingList does not sort. I did use the suggested site/ to get my list to sort. Thanks guys! My extension does work now.
这篇关于扩展IEnumerable返回BindingList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!