|
The TriggerTargetNavigator represents a delegate for navigating from the trigger object to the object being verified. The navigator can either be a path (PropertyDescriptor) or a custom method capable of bridging the two object types.
Here’s an example taken from the sample app accompanying the Verification Tutorial videos on the website, where the navigator is a path:
///<summary>Get the OrderDateAfterHired Verifier.</summary>
private static Verifier GetOrderDateAfterHiredVerifier() {
string description = "OrderDate must be after the sales rep's HireDate.";
DelegateVerifier<Order> v =
new DelegateVerifier<Order>(description, OrderDateAfterHiredCondition);
v.ExecutionModes = VerifierExecutionModes.InstanceAndOnPostsetTriggers;
v.AddTrigger(EntityPropertyDescriptors.Order.OrderDate);
v.AddTrigger(new TriggerLink(
EntityPropertyDescriptors.Employee.HireDate, // Triggered by Employee.HireDate
EntityPropertyDescriptors.Employee.Orders, // Path from trigger (Employee) to Order
true)); // True = that path returns multiple orders
return v;
} |
Here’s an example where the navigator is a custom method:
private static Verifier GetOrderDateDiscontinuedProductVerifier() {
string description = "No orders allowed for discontinued products after 1/1/1998";
DelegateVerifier<Order> v =
new DelegateVerifier<Order>(description, GetOrderDateDiscontinuedProductCondition);
v.ExecutionModes = VerifierExecutionModes.All;
v.AddTrigger(EntityPropertyDescriptors.Order.OrderDate);
v.AddTrigger(new TriggerLink(
EntityPropertyDescriptors.Product.Discontinued, // Triggered by Product.Discontinued
GetOrdersAssociatedWithProduct, // Method bridging orders and products
true); // True = that method returns multiple orders
return v;
}
private static EntityList<Order> GetOrdersAssociatedWithProduct(Object pProduct) {
Product aProduct = (Product)pProduct;
OrderDetail[] details = aProduct.GetChildren<OrderDetail>(
EntityRelations.Product_OrderDetail,
QueryStrategy.Normal);
EntityList<Order> orders = aProduct.PersistenceManager.GetParents<Order>(
details, EntityRelations.Order_OrderDetail, QueryStrategy.Normal);
return orders;
}
|
|