Navigation

Categories
Show Navigation Next Topic  »

IMPORTANT! Remember that only rules of evaluation type can be used in data filtering, where they are called filters.

Queryable.Filter method

Declaring Class: CodeEffects.Rule.Core.RuleExtensions
Namespace: CodeEffects.Rule.Core

Provides rule-based data filtering capabilities to Entity Framework. Uses the plain evaluator class.

Returns

IQueryable whose elements are filtered according to conditions set in the business rule.

Syntax

public static IQueryable Filter(
this IQueryable source,
Type type,
string rulesetXml,
string ruleId = null,
GetRuleDelegate getRule = null)

Type Parameters

  • source, System.Collections.IQueryable - A sequence of values of the source object's type to filter against the business rule.

Parameters

  • type, System.Type - Type of the source object that the rule was created with/for.
  • rulesetXml, System.String - This string can contain either a single Rule XML document, a single <rule> node that contains a rule, or a collection of rules called the ruleset.
  • ruleId, System.String - If the Rule XML passed in the previous parameter is a ruleset then this nullable parameter contains the ID of the particular rule located inside of that ruleset.
  • getRule, CodeEffects.Rule.Core.GetRuleDelegate - This nullable parameter takes a reference to a method that returns string Rule XML by rule ID. Pass this delegate if your rule may potentially reference reusable rules that are not stored in the same XML ruleset.

Queryable.Filter<TSource> method

Declaring Class: CodeEffects.Rule.Core.RuleExtensions
Namespace: CodeEffects.Rule.Core

Provides rule-based data filtering capabilities to Entity Framework. Uses the generic evaluator class.

Returns

IQueryable<TSource> whose elements are filtered according to conditions set in the business rule.

Syntax

public static IQueryable<TSource> Filter<TSource>(
this IQueryable<TSource> source,
string rulesetXml,
string ruleId = null,
GetRuleDelegate getRule = null)

Type Parameters

  • source, System.Collections.IQueryable<TSource> - A sequence of values of TSource type to filter against the business rule.

Parameters

  • rulesetXml, System.String - This string can contain either a single Rule XML document, a single <rule> node that contains a rule, or a collection of rules called the ruleset.
  • ruleId, System.String - If the Rule XML passed in the previous parameter is a ruleset then this nullable parameter contains the ID of the particular rule located inside of that ruleset.
  • getRule, CodeEffects.Rule.Core.GetRuleDelegate - This nullable parameter takes a reference to a method that returns string Rule XML by rule ID. Pass this delegate if your rule may potentially reference reusable rules that are not stored in the same XML ruleset.

Example

var q = from c in new YourDatabase().Customers.Filter<Customer>(ruleXmlString)
select new
{
	CustomerID = c.CustomerID,
	FirstName = c.FirstName,
	LastName = c.LastName,
	CompanyName = c.CompanyName,
	CellPhone = c.CellPhone,
	Email = c.Email,
	BillingStreet = c.BillingAddress.Street,
	BillingCity = c.BillingAddress.City,
	BillingState = c.BillingAddress.State
};

Post your questions on Stackoverflow and become a part of our growing community

Comments: 0