Support Linq

Class LinqToLcs namespace ICSSoft.STORMNET.Business.LINQProvider designed to support LINQ requests for data services SQLDataService.

Main features LINQProvider described in the article Features LinqProvider.

How to use LinqProvider

To enable LINQ-provider requires a reference to System.Linq

 using System.Linq;

And project link to ICSSoft.STORMNET.Business.MSSQLDataService.DLL.

When you connect the namespace ICSSoft.STORMNET.Business.LINQProvider objects SQLDataService is added to Query method with the following prototypes:

public static IQueryable<T> Query<T>(this SQLDataService ds, string viewName) where T : DataObject

public static IQueryable<T> Query<T>(this SQLDataService ds, View view, IEnumerable<View> resolvingViews = null) where T : DataObject

public static IQueryable<T> Query<T>(this SQLDataService ds) where T : DataObject

Parameters:

Name Description
ds Service data, the heir SQLDataService, to query
view View used to download
resolvingViews View masters containing their detaily used in the query (if there are none, then null)

In the latter case overload view to download the object will be formed dynamically (it will get the properties used in the query).

Thus, if the view is specified statically, it is preferable to use the second option overload, putting the view Тип.Views.ИмяТипа.

The method returns IQueryable that you can pass the query by using the methods-extensions to LINQ:

Examples of usage

the first suitable object

using ICSSoft.STORMNET.Business;
using ICSSoft.STORMNET.Business.LINQProvider;
//... 
var ds = (SQLDataService)DataServiceProvider.DataService; // The data service. 
Кошка cat = ds.Query<Кошка>(Кошка.Views.КошкаE).First(o => o.Кличка.Contains("Osh")); // Get the object. 
Console.WriteLine(cat.Кличка); //Use. 

the first suitable object (with the generation TOP 1 in the request body when using FirstOrDefault and First)

using ICSSoft.STORMNET.Business;
using ICSSoft.STORMNET.Business.LINQProvider;
//... 
var ds = (SQLDataService)DataServiceProvider.DataService; // The data service. 
Кошка cat = ds.Query<Кошка>(Кошка.Views.КошкаE).Where(o => o.Кличка.Contains("Osh")).Take(1).FirstOrDefault(); // Get the object. 
Console.WriteLine(cat.Кличка); //Use. 

a collection of objects

using ICSSoft.STORMNET.Business;
using ICSSoft.STORMNET.Business.LINQProvider;
//... 
var ds = (SQLDataService)DataServiceProvider.DataService; // The data service. 
IQueryable<Кошка> objs = ds.Query<Кошка>(Кошка.Views.КошкаE); 
IQueryable<Кошка> query = from o in objs where o.PrimaryKey == "6211E0DE-3E7A-4A68-866A-AB206A005B1C" select o; // Get the cats on a given key value. 
List<Кошка> data = query.ToList(); // Subtract data to the collection. 
Console.WriteLine(data[0).Кличка); // Use the received data. 

the Following code is equivalent to the previous

var ds = (SQLDataService)DataServiceProvider.DataService; // The data service. 
IQueryable<Кошка> objs = ds.Query<Кошка>(Кошка.Views.КошкаE).Where(o => o.PrimaryKey == "6211E0DE-3E7A-4A68-866A-AB206A005B1C"); // Get the cats on a given key value. 
List<Кошка> data = objs.ToList(); // Subtract data to the collection. 
Console.WriteLine(data[0).Кличка); // Use the received data.