ConcatenatedFieldList class

Provides a means for concatenating a list of IField objects.

Namespace: ReFlex.Data.Criterion namespace
Assembly: ReFlex.Data.dll

Syntax

public class ConcatenatedFieldList : List<IField>, IField

Constructors

ConcatenatedFieldList();

Remarks

Use for querying a concatenated list of IFields. For example if you wanted to compare tblContact.FirstName + ' ' + tblContact.LastName is like 'John', you could add a TextAffixField of FirstName with an ' ' suffix, and a Field of LastName.

Examples

public class ContactManager : ReFlex.Data.ManagerBase<Contact>
{
    /// <summary>
    /// Gets a list of Contact objects that have a FirstName+' '+LastName like John Smith, and
    /// a company name that equals the companyName input
    /// </summary>
    /// <param name="companyName"></param>
    /// <returns></returns>
    public List<Contact> GetJohnSmiths(string companyName)
    {
        if (string.IsNullOrEmpty(companyName))
            throw new ArgumentNullException("companyName");

        // specify a relationship that will be included in the Criterion
        // with strong parent (inner join) relationship type
        Relationship currentCompanyRelationship = new Relationship(typeof(Company), typeof(Contact), "CurrentCompany", RelationshipTypeEnum.StrongParent);
       
        // create query checking Contact's with full name like John Smith
        // and CurrentCompany.CompanyName equals companyName
        ConcatenatedFieldList nameList = new ConcatenatedFieldList()
        nameList.Add(new TextAffixField(new Field<Contact>("FirstName"), null, " "));
        nameList.Add(new Field<Contact>("LastName"));

        Criterion<Contact> criterion = new Criterion<Contact>(CriteriaOperatorEnum.And)
            .Add(nameList, "John Smith", ComparisonOperatorEnum.Like, CriteriaOperatorEnum.And)
            .Add(new Field<Company>("CompanyName", "CurrentCompany"), companyName, ComparisonOperatorEnum.Equals, CriteriaOperatorEnum.And);

        // specify how the results should be ordered using the Ordering object
        Ordering ordering = new Ordering()
            .Add<Contact>("LastName", Direction.Ascending)
            .Add<Contact>("FirstName", Direction.Ascending);

        // instantiate ObjectFactory and run the query, catching the
        // resulting list of matching Contact objects
        List<Contact> contacts;
        using (ObjectFactory<Contact> mapper = new ObjectFactory<Contact>())
            contacts = mapper.GetDataObjects(criterion, ordering, currentCompanyRelationship);

        return contacts;
    }
}