Skip to content
This repository has been archived by the owner on Aug 18, 2020. It is now read-only.

Query comparison

Matthijs Wagemakers edited this page Dec 28, 2016 · 1 revision

Fetching a list of persons

Fetching a list of (max) 10 persons for company '2', ordered by last name.

Without SuperLinq:

using (ArchiveAgent aa = new ArchiveAgent())
{
    ArchiveListItem[] results = aa.GetArchiveListByColumns("dynamic", //providerName
            new[] { "person.person_id", "person.lastname" }, //columns
            new[] { new ArchiveOrderByInfo { Name = "person.lastname", Direction = OrderBySortType.ASC } }, //order
            new[] { new ArchiveRestrictionInfo("person.contact_id", "=", "2") }, //restrictions
            null, //entities
            0,    //page
            10); //page size

    foreach (ArchiveListItem item in results)
    {
        int personId = CultureDataFormatter.ParseEncodedInt(item.ColumnData["person.person_id"].DisplayValue);
        string lastName = item.ColumnData["person.lastname"].DisplayValue;
    }
}

With SuperLinq:

List<Person> persons = new Queryable<Person>()
    .Where(where => where.ContactId == 2)
    .OrderBy(order => order.Lastname)
    .Take(10)
    .ToList();
                    
foreach (Person person in persons)
{
    int personId = person.PersonId;
    string lastName = person.Lastname;
}

Using parenthesis

Using parenthesis can be slightly difficult without SuperLinq. In the example below we fetch a list of company in the Netherlands with a name that starts with SuperOffice, InfoBridge or ACME:

using (ArchiveAgent aa = new ArchiveAgent())
{
    ArchiveListItem[] results = aa.GetArchiveListByColumns("dynamic",
            new[] { "contact.contact_id", "contact.name" },
            null,
            new[] {
                    new ArchiveRestrictionInfo("contact.name", "begins", "SuperOffice") { InterOperator = InterRestrictionOperator.Or, InterParenthesis = 1 },
                    new ArchiveRestrictionInfo("contact.name", "begins", "InfoBridge") { InterOperator = InterRestrictionOperator.Or, InterParenthesis = 0 },
                    new ArchiveRestrictionInfo("contact.name", "begins", "ACME") { InterOperator = InterRestrictionOperator.And, InterParenthesis = -1 },
                    new ArchiveRestrictionInfo("contact.country_id", "=", "528") { InterOperator = InterRestrictionOperator.And, InterParenthesis = 0 },
            },
            null,
            0,
            100);
}

With SuperLinq:

List<Contact> companies = new Queryable<Contact>()
    .Where(c =>
        (c.Name.StartsWith("SuperOffice") || c.Name.StartsWith("InfoBridge") || c.Name.StartsWith("ACME")) &&
        c.CountryId == 528)
    .ToList();
Clone this wiki locally