In-memory filtering + new entities

Posts   
 
    
Posts: 69
Joined: 24-Jun-2008
# Posted on: 19-Oct-2009 16:10:58   

Probably this question is asked before, but I couldn't find any information since the search function of this forum is not the best I have ever seen.

I have this problem: in memory, I create some collections that are related to eachother, but I initially retrieve all the collections via the GetMulti(null).

Now, I add a new entity to Customer, which works perfect. Then, I want to filter _Order _based on the new entity created in Customer. Therefore, I dynamically create this predicate:

IPredicate filter = new PredicateExpression(OrderFields.CustomerID == justCreatedCustomer.CustomerID);

However, this is not going to work since _justCreatedCustomer.CustomerID _currently equals 0. Is there any way I can still create a filter, even though I did not yet store the newly created entities to the database?

Thanks in advance!

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 19-Oct-2009 17:22:28   

If you are adding the new customerto a graph and you have already addedsome orders to this customer (since you want to get Orders of this Customer). Then why don't you just use Customer.Orders collection.

If that's not possible, then please explain why and post code snippets of how you build your graph, create the customer ...etc.

Posts: 69
Joined: 24-Jun-2008
# Posted on: 20-Oct-2009 10:08:37   

What I have is about 7 tables, all in a 1:n relation. I have a filter list (combobox) where I select the parent, and I store all the separate collections in a dictionary:

Dictionary<ManageableEntityType, IEntityCollection> _entityCollections;

(ManageableEntityType is a custom enum containing all the supported entity types).

Then, I dynamically create a predicate and use the _CreateView _method to create a view on the collection with a filter to the selected parent. This does not work when a new entity has just been added (then, the item is not filtered).

What I am trying now is to register the parent type for each collection as well in a custom class. Then, I know which parent to use and which collection of that parent to use. It seems to work good that way, but requires some additional code. I hoped it was possible to create a predicate something like this:

new PredicateExpression(OrderFields.Customer == Customer);

instead of

new PredicateExpression(OrderFields.CustomerID == CustomerID);
Posts: 69
Joined: 24-Jun-2008
# Posted on: 20-Oct-2009 11:09:54   

Update:

I think I was able to fix it with a DelegatePredicate. I use this:

filter.AddWithAnd(new DelegatePredicate(delegate(IEntityCore toExamine)
    {
        return ((Order)toExamine).Customer.Equals(entity);
    }));

entity is a dynamically determined entity that, in this case, is a customer, but can be a lot of different domain data entity types.

I prefer this over the previously posted solution because now I can control the removed entities in the collections directly, which is not possible with the previous solution.