use filter of bindingSource with Entity Framework

bindingsource, c#, entity-framework

Solution

Every BindingSource has a property SupportsFiltering (and SupportsSorting). In case you set an entitySet as DataSource these two properties are automatically set to false! So there are some possible solutions. Either you provide an extension method to your `IEnumberable<T>` as shown here or you choose to filter/sort using `Linq2Entities`.

Snippet for Linq2Entities could be:

myEntity context = new myEntity();
myBindingSource.DataSource = (from m in context.myTable
                              where m.PROPERTY MEETS CONDITION
                              select m).ToList<TYPE>();

Snippet for extension method:

// extension method
public static IEnumerable<T> Filter<T>(this IEnumerable<T> list, Func<T, bool> filterParam) {
        return list.Where(filterParam);
}

// filtering example
context.myTable.Filter(x => x.ItemName.StartsWith("Test"))

Furthermore this subject has been discussed many times before, even here on SO.

Problem

I working on a C# win-form app. in my form i have Data-Grid-View that bind with a Binding-Source and Binding-Source Data-source is a table of entity-framework. when i use entity framework i cant use filter of the binding-source and the sort by columns of data-grid-view but when i don't use entity framework i can use them. how can i use them with entity-framework? my code when form loads is ``` contex = new myEntity(); myBindingSource.DataSource = contex.myTable; ```

Original source

Related problems