Re-applying a FilterDefinition
I have an application which models the electrical distribution of a system whereby if certain of the components fail the routing is automatically rerouted. I've modelled this by adding a connection entity that has an ID to the parent component and an ID to the child component. The idea is that for the items that may fail there is a connection for the normal working condition and another connection for each failed situation. For example, if there are 40 components of which 9 may fail then I have 2^9 (512) possible failures and 2^9 connection entities for each component. Each connection is named for the failure mode that it represents.
So far, so good, very flexible and works.
However, every time that the bus diagram is loaded all the connections are loaded resulting in 40 * 512 (20480) connection entities when only 40 are needed for the current failure mode and, not surprisingly, this is causing the application to hog resources and run slowly.
So, I have defined a FilterDefinition to restrict the connections loaded to the required named connection if the component is of a particular type and the normal connection if it is any other type and added this to the connections collection mapping of the component enabled the filter and set the parameter.
public FailureModeFilter()
{
WithName("FailureName")
.WithCondition("((Name = :name and ObjectType <> 8) or
(Name = 'Normal' and ObjectType = 8))")
.AddParameter("name", NHibernateUtil.String);
}
And not at all surprisingly, this works.开发者_如何学编程
But, and you knew there was going to be a snag didn't you?
But, when a new failure mode is chosen and the diagram reloaded, it doesn't apply the new filter but retains the old one. I've tried setting the new parameter, disabling the filter, enabling it again and setting the pararmeter all to no avail.
So, what am I doing wrong/failing to do/misunderstanding (delete as applicable) or, failing that, any suggestions as to how to solve this?
The same session is being used while the diagram is open. Yes, I know that isn't the suggested best practise, but for other reasons it is the best solution for this part of the application. Please don't get side-tracked about this telling me about how this is bad practise with doom, gloom and depondency as I already know. The question is about the changing of the filter.
Answered my own question for a change.
This answer is to refresh the component to force a reload from the database.
session.Refresh(entity);
So simple when you figure it out!
精彩评论