[]
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 file to map the Incident datatable.
Retrieve all entities that contain "Server" in the Description column.
var records = context.Incident.Where(x => x.Description.Contains("Server"));
Sort data by Category in ascending order.
var records = (from p in context.Incident
orderby p.Category ascending//Implementing Order By
select p);
Count all entities that match a given criterion.
var _count = (from p in context.Incident
select p).Count();//Count Query based on number of records selected
Cross-join Incident and AlmAsset tables.
var records = from b in context.Incident
from e in context.AlmAsset
select new { b, e };//Defining Cross Join
Group records from the Incidents table based on the Category property.
var incidentTable = context.Incident.AsEnumerable();
var queryIncident = from b in incidentTable
group b by b.Category into newGroup
orderby newGroup.Key descending
select newGroup;