LINQ Provider
Use the GridGain.NET LINQ provider to write distributed SQL queries in C# with LINQ, including projections, joins, and compiled queries.
Overview
GridGain.NET includes a LINQ provider that is integrated with GridGain SQL APIs. You can avoid dealing with SQL syntax directly and write queries in C# with LINQ. The GridGain LINQ provider supports all features of ANSI-99 SQL including distributed joins, groupings, aggregates, sorting, and more.
Installation
If you use the GridGain binary distribution: add a reference to
Apache.Ignite.Linq.dllIf you use NuGet:
Install-Package Apache.Ignite.Linq
Configuration
SQL indexes need to be configured the same way as for regular SQL queries, see Defining Indexes section for details.
Usage
Apache.Ignite.Linq.CacheLinqExtensions class is an entry point for the LINQ provider. Obtain a queryable instance over an GridGain cache by calling the AsCacheQueryable method, and use LINQ on it:
ICache<EmployeeKey, Employee> employeeCache = ignite.GetCache<EmployeeKey, Employee>(CacheName);
IQueryable<ICacheEntry<EmployeeKey, Employee>> queryable = cache.AsCacheQueryable();
Employee[] interns = queryable.Where(emp => emp.Value.IsIntern).ToArray();AsCacheQueryable also accepts a QueryOptions object to configure query behavior. For example, use the Label property to identify the query in system views and long-running query warnings (see SQL Query Labels):
Introspection
The GridGain LINQ provider uses ICache.QueryFields underneath. You can examine produced SqlFieldsQuery by casting IQueryable to ICacheQueryable at any point before materializing statements (ToList, ToArray, etc):
Projections
Simple Where queries operate on ICacheEntry objects. You can select Key, Value, or any of the Key and Value fields separately. Multiple fields can be selected using anonymous types.
Compiled Queries
The LINQ provider causes certain overhead caused by expression parsing and SQL generation. You may want to eliminate this overhead for frequently used queries.
The Apache.Ignite.Linq.CompiledQuery class supports queries compilation. Call the Compile method to create a new delegate to represent the compiled query. All query parameters should be in the delegate parameters.
Refer to the LINQ vs SQL blog post for more details on the LINQ provider performance.
Joins
The LINQ provider support JOINs that span several caches/tables and nodes.
Contains
ICollection.Contains is supported, which is useful when we want to retrieve data by a set of ids, for example:
This query translates into the ... where Id IN (?, ?, ?) command. However, keep in mind, that this form cannot be used in compiled queries because of variable argument number. Better alternative is to use Join on the ids collection:
This LINQ query translates to a temp table join: select _T0._KEY, _T0._VAL from "person".Person as _T0 inner join table (F0 int = ?) _T1 on (_T1.F0 = _T0.ID), and has a single array parameter, so the plan can be cached properly, and compiled queries are also allowed.
Supported SQL Functions
Below is a list of .NET functions and their SQL equivalents that are supported by the GridGain LINQ provider.
String.Length
LENGTH
String.ToLower
LOWER
String.ToUpper
UPPER
String.StartsWith("foo")
LIKE 'foo%'
String.EndsWith("foo")
LIKE '%foo'
String.Contains("foo")
LIKE '%foo%'
String.IndexOf("abc")
INSTR(MyField, 'abc') - 1
String.IndexOf("abc", 3)
INSTR(MyField, 'abc', 3) - 1
String.Substring("abc", 4)
SUBSTRING(MyField, 4 + 1)
String.Substring("abc", 4, 7)
SUBSTRING(MyField, 4 + 1, 7)
String.Trim()
TRIM
String.TrimStart()
LTRIM
String.TrimEnd()
RTRIM
String.Trim('x')
TRIM(MyField, 'x')
String.TrimStart('x')
LTRIM(MyField, 'x')
String.TrimEnd('x')
RTRIM(MyField, 'x')
String.Replace
REPLACE
String.PadLeft
LPAD
String.PadRight
RPAD
Regex.Replace
REGEXP_REPLACE
Regex.IsMatch
REGEXP_LIKE
Math.Abs
ABS
Math.Acos
ACOS
Math.Asin
ASIN
Math.Atan
ATAN
Math.Atan2
ATAN2
Math.Ceiling
CEILING
Math.Cos
COS
Math.Cosh
COSH
Math.Exp
EXP
Math.Floor
FLOOR
Math.Log
LOG
Math.Log10
LOG10
Math.Pow
POWER
Math.Round
ROUND
Math.Sign
SIGN
Math.Sin
SIN
Math.Sinh
SINH
Math.Sqrt
SQRT
Math.Tan
TAN
Math.Tanh
TANH
Math.Truncate
TRUNCATE
DateTime.Year
YEAR
DateTime.Month
MONTH
DateTime.Day
DAY_OF_MONTH
DateTime.DayOfYear
DAY_OF_YEAR
DateTime.DayOfWeek
DAY_OF_WEEK - 1
DateTime.Hour
HOUR
DateTime.Minute
MINUTE
DateTime.Second
SECOND
This page is: Copyright © 2026 MariaDB. All rights reserved.
Last updated
Was this helpful?

