DataConnector
LINQ クエリ
ADO.NET provider for ServiceNow > LINQ クエリ

LINQ queries demonstrate how to operate and query the Service Now objects wrapped in an Entity Framework data model. Listed below are some examples of LINQ queries supported by the Entity framework. In the following example, it is used Incident.cs file to map the Incident datatable.

Contains

Retrieve all entities that contains "Server" in the Description column.

C#
コードのコピー
var records = context.Incident.Where(x => x.Description.Contains("Server"));

Order By

Sort data by Category in ascending order.

C#
コードのコピー
var records = (from p in context.Incident
               orderby p.Category ascending// Order Byの実装
               select p);

Count

Count all entities that match a given criterion. 

C#
コードのコピー
var _count = (from p in context.Incident
              select p).Count();//選択されたレコードの数に基づいてクエリをカウントします。

Joins

Cross join Incident and AlmAsset tables.

C#
コードのコピー
var records = from b in context.Incident
              from e in context.AlmAsset
              select new { b, e };//クロス結合を定義します。
Group By

Group records from the Incidents table based on the Category property.

C#
コードのコピー
 var incidentTable = context.Incident.AsEnumerable();
 var queryIncident = from b in incidentTable
                     group b by b.Category into newGroup
                     orderby newGroup.Key descending
                     select newGroup;