Sage.Platform.RepositoryHelper<Sage.Entity.Interfaces.IAccount> rep = Sage.Platform.EntityFactory.GetRepositoryHelper<IAccount>();
Sage.Platform.Repository.ICriteria criteria = rep.CreateCriteria();
criteria.Add(rep.EF.Or(rep.EF.Eq("Status","Active"),rep.EF.Eq("Type","Customer")));
System.Collections.IList result = criteria.List();
In this example we will use the ExpressionFactory OR statement. This example creates a List that has All Accounts where the Status = Active OR where the Type = Customer. We will use Sage.Platform.Repository with ICriteria to create the query returning the results into a generic list.
In the code example below, the first line gets a repository for IAccount using the RepositoryHelper class. We use the RepositoryHelper class because it creates the ExpressionFactory (seen as EF) and the ProjectionFactory (not seen but as PF) for us without additional lines of code that would exist if we used Repository instead of RepositoryHelper. Using RepositoryHelper also lets us use CreateCriteria method directly from the repository (see line 2 below).
Now for the use of the OR in our criteria. First we add a new criteria using criteria.Add method. Since we have an OR condition we then use the repository’s Expression Factory to access the OR, then we place 2 expressions as parameters. Seen below is rep.EF.Or with 2 expressions: the first expression is rep.EF.Eq with Status = “Active”, the next is rep.EF.Eq with Type = “Customer”. It is easy to think of this in terms of what the result would look like in SQL: Where Status = “Active” OR Type = “Customer”.
The final line brings back the result set from ICriteria into a generic List.
Related Video Short! from the SalesLogix Developer’s Subscription:


September 1, 2009
[...] http://slxtraining.net/2009/09/expressionfactory_or/ [...]