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

Getting started

Matthijs Wagemakers edited this page Apr 26, 2017 · 11 revisions

Installation

In order to get started with SuperLinq simply install the NuGet package in your project:

install-package InfoBridge.SuperLinq

SuperLinq only works with the SuperOffice NetServer Services. Setting this up is out of scope for this document so make sure to read the SuperOffice documentation. Note that you do not need to add the NetServer dlls and config file: this is done automatically by the SuperOffice NetServer Services NuGet package that is referenced by SuperLinq.

After you verified that you have successfully authenticated with the NetServer services you can move on to the next section.

Query a single table

SuperLinq comes with a class for each table in the SuperOffice database. These classes are located in the namespace InfoBridge.SuperLinq.Core.Models. Each class model is a direct copy of a table in the SuperOffice database with all columns. These models can used to both generate the query and to parse/return the results.

The base for all LINQ queries is the InfoBridge.SuperLinq.Core.Queryable class. By creating a new instance of the Queryable class and specifying a model (table) you can initiate the query building.

In the example below we query the person table and fetch all persons for a company with id '2':

using InfoBridge.SuperLinq.Core;
using InfoBridge.SuperLinq.Core.Models;

...

List<Person> contactPersons = new Queryable<Person>()
    .Where(person => person.ContactId == 2)
    .ToList();

Fetching a single result is done by using Single(), SingleOrDefault(), First() or FirstOrDefault() methods. In the example below we fetch the first result from all companies that are created today with a name that starts with Super:

Contact contact = new Queryable<Contact>()
    .Where(contact => contact.Registered > DateTime.Now.Date && contact.Name.StartsWith("Super"))
    .OrderByDescending(order => order.Registered)
    .FirstOrDefault();

Check out the other query examples.

Custom models

In certain cases it could be useful to query other tables than those supplied in InfoBridge.SuperLinq.Core.Models, for example for querying custom tables, for efficient querying on multiple tables or for querying archive providers.

Example, we have a custom Service table called y_equipment with 2 columns: x_name and x_location. The class should then look like this:

using InfoBridge.SuperLinq.Core.Attributes;
using InfoBridge.SuperLinq.Core.ModelBase;

namespace Example
{
    [TableInfo("y_equipment")]
    public class Equipment : IModel
    {
        [ColumnInfo("id")]
        public int Id { get; set; }

        [ColumnInfo("x_name")]
        public string Name { get; set; }

        [ColumnInfo("x_location")]
        public string Location { get; set; }
    }
}

The query to get an equipment with the name 'Printer 01' could then look like this:

Equipment eq = new Queryable<Equipment>().FirstOrDefault(e => e.Name == "Printer 01");

For more information check out custom query models.

Querying archive providers

SuperLinq will query the dynamic archive provider by default. However, this can be overridden by supplying an archive provider name to the constructor of the InfoBridge.SuperLinq.Core.Queryable class. You can specify all archive providers supported by NetServer, found here.

For more information and examples check out querying archive providers.

Clone this wiki locally