On this page
Besides the standard LINQ operators, dotConnect for Snowflake translates the following .NET members to Snowflake SQL:
- String members: Length, Contains, StartsWith, EndsWith (with a string argument or a constant char argument), IndexOf(string), Substring, Replace, ToUpper, ToLower, Trim, TrimStart, TrimEnd (without arguments; all white-space characters are removed, as in .NET), string.IsNullOrEmpty, string.IsNullOrWhiteSpace, string.Concat and the + operator (a null string is concatenated as an empty string, as in .NET).
- Regex.IsMatch(input, pattern): the pattern is searched anywhere in the string, as in .NET.
- Math methods: Abs, Ceiling, Floor, Truncate, Max, Min, Pow, Sqrt, Exp, Log, Log10, Sign, Sin, Cos, Tan, Asin, Acos, Atan, Atan2, and Round. Math.Round rounds a midpoint value to the nearest even number (banker's rounding), as in .NET; Math.Round with MidpointRounding.AwayFromZero is also supported. Integer division and conversion of a fractional number to an integer truncate the value, as in C#.
- DateTime and DateTimeOffset members: Year, Month, Day, Hour, Minute, Second, Millisecond, DayOfYear, DayOfWeek, Date (DateTime only), AddYears, AddMonths, AddDays, AddHours, AddMinutes, AddSeconds, AddMilliseconds. DateTime.UtcNow and DateTimeOffset.UtcNow are translated to the current time on the server.
- DateOnly and TimeOnly members (Entity Framework Core 8 and higher): the date and time parts, DateOnly.AddDays, AddMonths, AddYears, ToDateTime(TimeOnly), DateOnly.FromDateTime, TimeOnly.FromDateTime, TimeOnly.FromTimeSpan, TimeOnly.AddHours, and TimeOnly.AddMinutes.
- string.Join(separator, group.Select(...)) in a GroupBy query or over a navigation collection (Entity Framework Core 8 and higher): translated to LISTAGG. Distinct and OrderBy inside string.Join aren't supported.
The EF.Functions property provides the following Snowflake-specific methods (the SnowflakeDbFunctionsExtensions class). They can be used only in LINQ to Entities queries; a direct call throws InvalidOperationException.
Method | SQL |
| bool ILike(string matchExpression, string pattern) | Case-insensitive LIKE: matchExpression ILIKE pattern. |
int DateDiffYear(DateTime startDate, DateTime endDate) int DateDiffMonth(DateTime startDate, DateTime endDate) int DateDiffDay(DateTime startDate, DateTime endDate) | DATEDIFF(year | month | day, startDate, endDate): the number of year, month, or day boundaries between the dates. |
long DateDiffHour(DateTime startDate, DateTime endDate) long DateDiffMinute(DateTime startDate, DateTime endDate) long DateDiffSecond(DateTime startDate, DateTime endDate) | DATEDIFF(hour | minute | second, startDate, endDate): the number of hour, minute, or second boundaries between the values. |
|
|---|
var start = new DateTime(2024, 1, 1);
var orders = context.Orders
.Where(o => EF.Functions.ILike(o.CustomerName, "%smith%"))
.Select(o => new { o.Id, Days = EF.Functions.DateDiffDay(start, o.OrderDate) })
.ToList();
|
The following query constructs aren't supported:
- A correlated subquery with First, FirstOrDefault, Single, Take, or Skip over the related rows inside the projection or the filter of another query. Snowflake can't evaluate such subqueries, so the provider throws NotSupportedException. Rewrite the query with an aggregate (Min, Max, Count), load the related rows with Include and select them on the client, or query them separately.
- DateTime.Now and DateTime.Today aren't translated, because the time zone of the Snowflake session may differ from the time zone of the client. Assign the value to a local variable before the query and use the variable in the query, or use DateTime.UtcNow.