locked
Exclude object from results on ObjectMaterialized RRS feed

  • Question

  • Is there some way to exclude object from query results in ObjectMaterialized event handler?
    Monday, November 28, 2011 4:04 PM

Answers

  • Hi,

    Why not filter them out instead in the query? There is a overhead getting them and then handling them?

    The ObjectMaterialized event is called before it is added to the collections, so I can't see any way to exclude it at that point. However, the object is added to the contexts ObjectStateManager before this stage, so what you can do is to detach it from the context in your ObjectMaterialized function, and then filter them out afterwards.

    But again, you can then as easily either filter them out in the query or do a query on the result list afterwards the result is materialized and then filter them out.


    --Rune

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful" if the post helped you to a solution of your problem.
    Monday, November 28, 2011 5:15 PM

All replies

  • Hi,

    Why not filter them out instead in the query? There is a overhead getting them and then handling them?

    The ObjectMaterialized event is called before it is added to the collections, so I can't see any way to exclude it at that point. However, the object is added to the contexts ObjectStateManager before this stage, so what you can do is to detach it from the context in your ObjectMaterialized function, and then filter them out afterwards.

    But again, you can then as easily either filter them out in the query or do a query on the result list afterwards the result is materialized and then filter them out.


    --Rune

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful" if the post helped you to a solution of your problem.
    Monday, November 28, 2011 5:15 PM
  • Thanks for reply,

    Unfortunatelly, it looks like there are no transparent for higher level layer way to intercept queries too.

    Tuesday, November 29, 2011 2:21 PM