This is a migrated thread and some comments may be shown as answers.

navigation property filtering

1 Answer 42 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Kai
Top achievements
Rank 1
Kai asked on 27 Jan 2014, 07:22 PM
Hi,

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)
                    {
                        Console.WriteLine(orderDetail.OrderID);
                    }

I can not filter on the foreach loop. it must be filtered before.

1 Answer, 1 is accepted

Sort by
0
Jan Blessenohl
Telerik team
answered on 28 Jan 2014, 11:21 AM

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.



Regards,

Jan Blessenohl
Telerik
Telerik has recently updated some of its product names. You can check out the Telerik Product Map here (www.telerik.com/name-mapping). OpenAccess ORM is now renamed to Telerik Data Access.
Tags
General Discussions
Asked by
Kai
Top achievements
Rank 1
Answers by
Jan Blessenohl
Telerik team
Share this question
or