Client Interfaces Guide > TIBCO ADO.NET 2020 Data Provider for TDV > Using ADO.NET (LINQ) > LINQ Queries
 
LINQ Queries
Below are examples of LINQ queries supported by the provider.
Select and Filter
The following query searches for records that have a value of "Konbu" for the ProductName column.
 
var query = from Products in context.Products
where Products.ProductName == "Konbu"
select Products;
Contains
You can also search for strings within strings: The following example retrieves all Products entities with a value that contains "B" in the ProductName column.
 
var query = from Products in context.Products
where Products.ProductName.Contains("B")
select Products;
Limit
The following example limits the results returned to 10.
 
var query = (from Products in context.Products
orderby Products.ProductName descending,
Products.ProductName ascending
select Products).Take(10);
Order By
The following example executes a multicolumn sort: Results are sorted by Id in ascending order (the default), then by ProductName in descending order.
 
var query = from Products in context.Products;
orderby Products.Id,
Products.ProductName descending
select Products;
Count
The following example counts all entities that match a given criterion.
 
int count = (from Products in context.Products
where Products.ProductName == "Konbu"
select Products).Count();
Group and Summarize
The following example calculates the minimum Price for a collection of entities grouped by ProductName, the key defined in the group clause.
 
var query = from Products in context.Products
group Products by new { Products.ProductName }
into g
orderby g.Key
select new {
ProductName = g.Key.ProductName,
MinPrice = g.Min(x => x.Price)
};
Joins
The following is an example of an inner join. The following query returns the Names of all Accounts that have Contacts and the Names of those Contacts:
 
var AccountsQuery = from accounts in context.Accounts
join contacts in context.Contacts on accounts.Id equals contacts.AccountId
select new
{
AccountName = accounts.Name,
ContactName = contacts.Name
};
The following is an example of a left outer join. The query returns the Names for all Accounts along with the Names of any associated Contacts:
var AccountsQuery = from accounts in context.Accounts
join contacts in context.Contacts on accounts.Id equals contacts.AccountId into Inners
from od in Inners.DefaultIfEmpty()
select new
{
AccountName = accounts.Name,
ContactName = od.ContactName
};
The following is an example of a cross join. The query combines every row from the Employees table with every row from the sales territories table and then projects the FirstName, LastName, and TerritoryDescription columns over these rows:
var infoQuery =
from emp in context.Employees
from empterr in context.EmployeeTerritories
select new
{
emp.FirstName,
emp.LastName,
empterr.TerritoryDescription
};