none
ObjectSet<TEntity> as the source of a CollectionView doesnt support filtering RRS feed

  • Question

  • Im trying to filter my products using a Predicate<object> like this:

    //ObjectContext

    MyDBEntities myDB = new MyDBEntities();

    CollectionViewSource myCVS = new CollectionViewSource();
    myCVS.Source = myDB.Products;
    CollectionView myCV = (CollectionView)myCVS.View;

    //this next line throws a NotSupportedException

    myCV.Filter = new Predicate<object>(MenuFilterPredicate);

    I also checked the CanFilter property of the View and it's set to false. Im guessing the problem is with ObjectSet<Product> tha does not support filtering. Im using EF4.0.

    Wha am i doing wrong?

    Wednesday, March 7, 2012 3:59 PM

Answers

  • Hi all, thanks for answering.

    I didnt want to edit the generated code by EF so i wrapped the ObjectSet<T> in an ObservableCcollection and its working now.

    Probably it didn't support filtering before because ObjectSet<T> doesnt implement INotifyCollectionChanged in my EF4 version (4.0)


    Thursday, March 15, 2012 1:04 AM

All replies

  • I have had this problem in the past, If I remember correctly you can set the getter method in the EF classes to return IENUMERABLE<ofType> instead of OBJECTSET.. 

    JP Cowboy Coders Unite!

    Wednesday, March 7, 2012 4:51 PM
  • Hi agugglez,

    Welcome to MSDN Forum.

    Does Mr. Javman's solution can help you to solve the issue?

    Best Regards


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Friday, March 9, 2012 2:08 AM
    Moderator
  • let me ask one more question: What is the type of myDB.Products?

    JP Cowboy Coders Unite!

    Friday, March 9, 2012 2:54 AM
  • Hi agugglez,

    Have you solved the issue?


    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Monday, March 12, 2012 2:16 AM
    Moderator
  • Hi all, thanks for answering.

    I didnt want to edit the generated code by EF so i wrapped the ObjectSet<T> in an ObservableCcollection and its working now.

    Probably it didn't support filtering before because ObjectSet<T> doesnt implement INotifyCollectionChanged in my EF4 version (4.0)


    Thursday, March 15, 2012 1:04 AM