NRules (Rule Builder), how to dynamic create rules for query statements?

306 views
Skip to first unread message

ARPIT GARG

unread,
Jun 7, 2019, 6:25:01 AM6/7/19
to NRules Users

I want to create a rule in rule builder, the rule which I want to create uses query method. How to create the same type of rule in Rule-Builder?
I want to achieve this using rule-builder. How can I create this type of rule dynamically in rule-builder?

public class LargeTotalRule : Rule
{
public override void Define()
{
Customer customer = null;
IEnumerable orders = null;
double total = 0;

    When()
        .Match<Customer>(() => customer, c => c.IsPreferred)
        .Query(() => orders, x => x
            .Match<Order>(
                o => o.Customer == customer,
                o => o.IsOpen)
            .Collect())
        .Let(() => total, () => orders.Sum(x => x.Amount))
        .Having(() => total > 100);

    Then()
        .Do(ctx => Console.WriteLine("Customer {0} has orders over $100 total", customer.Name));
}

}

Sergiy Nikolayev

unread,
Jun 7, 2019, 6:25:17 PM6/7/19
to NRules Users
Reply all
Reply to author
Forward
0 new messages