Dynamic LINQ: Pankaj Kumar Gupta Senior Software Engineer Miri Infotech (P) LTD, India
Dynamic LINQ: Pankaj Kumar Gupta Senior Software Engineer Miri Infotech (P) LTD, India
PANKAJ KUMAR GUPTA Senior Software Engineer Miri Infotech (P) Ltd, India Click to edit Master subtitle style
4/18/12
LINQ to SQL is an extension of LINQ that allows developers to write "queries" in .NET to retrieve and manipulate data from a SQL Server database. This gives the ability to access relational database objects as normal .Net objects. LINQ to SQL integrates SQL based schema definitions to the common language runtime (CLR) type system. 4/18/12 22 This provides strong typing, syntax
Normally LINQ queries constructed by using language operators or typesafe lambda extension methods. but the dynamic query library provides us with string based extension methods, where we will pass the expressions in string format. The Dynamic Expression API is present in the System.Linq.Dynamic namespace. This API provides classes:
33
4/18/12
The Dynamic Expression API provides the following IQueryable Extension Methods as part of System.Linq.Dynamic.DynamicQuery able class for dynamically querying objects.
public static IQueryable Where(this IQueryable source, string predicate, params object[] values); public static IQueryable<T> Where<T>(this IQueryable<T> source, string predicate, params object[] values); 4/18/12 44
Constructing Dynamic Queries using IQueryable extension Methods DataClassesDataContext db=new DataClassesDataContext(); var products = from p in db.Products where p.Model == "SD1000" && p.onsale==true select p;
4/18/12 55
DataClassesDataContext db=new DataClassesDataContext(); var product = from p in db.Products where p.Model == "SD1000" && p.onsale == true orderby p.Name select new { p.ItemId, p.Name, p.Model1, p.onsale };
DataClassesDataContext db = new
66
The Take() extension method is used to select a no of rows from the query result and Skip() extension method is used to skip no of rows from the query result.
DataClassesDataContext db=new DataClassesDataContext(); string condition = "Model==\"SD1000\" && onsale==true "; var product2 = 4/18/12 88
JOINS in LINQ
There is no direct support for Joins using the extension methods provided in the Dynamic Expression API. However one can use joins indirectly by using inner queries, where the inner queries can be constructed using Dynamic Expression API like below.
4/18/12
DataClassesDataContext db=new
99
4/18/12
1010