navigation property filtering

Thread is closed for posting
2 posts, 0 answers
  1. Kai
    Kai avatar
    1 posts
    Member since:
    Jan 2014

    Posted 27 Jan 2014 Link to this post


    is it possible to filter the loaded navigation properties? I want to to set some entities as deleted and exclude them if I query over the navigation property.

                    var product = context.Products.Include(x=>x.OrderDetails.Where(od=>od.IsDeleted)).FirstOrDefault(x => x.ProductID == 1);
                   foreach (var orderDetail in product.OrderDetails)

    I can not filter on the foreach loop. it must be filtered before.
  2. Jan Blessenohl
    Jan Blessenohl avatar
    707 posts

    Posted 28 Jan 2014 Link to this post

    Hello Kai,

    We do not allow filtering of persistent collections, our change tracking algorithm would be broken in filtered scenarios.

    The best way to achieve this is to have a persistent property AllOrderDetails and add a transient property

    public IEnumerable<OrderDetails> { get{return AllOrderDetails.Where(x=>x.Deleted == false).ToList();}}

    I know that this only works in certain scenarios. If it does not work for you, please describe your use case so that we can find a better solution.


    Jan Blessenohl
    Telerik has recently updated some of its product names. You can check out the Telerik Product Map here ( OpenAccess ORM is now renamed to Telerik Data Access.
Back to Top