Sql

Sql

该系列函数可用在 Where、Select、Having 等方法的表达式树中。

public static class Sql
{
    /* 使用此方法与双等号(==)的区别是:a => Sql.Equals(a.Name, a.XName) 会被翻译成 a.Name == a.XName,
       而 a => a.Name == a.XName 则会被翻译成 a.Name == a.XName or (a.Name is null and a.XName is null) */
    public static bool Equals<T>(T value1, T value2);
    /* 使用此方法与不等号(!=)的区别是:a => Sql.NotEquals(a.Name, a.XName) 会被翻译成 a.Name &lt;&gt; a.XName,
       而 a => a.Name != a.XName 则会被翻译成 a.Name &lt;&gt; a.XName or (a.Name is null and a.XName is not null) or (a.Name is not null and a.XName is null) */
    public static bool NotEquals<T>(T value1, T value2)

    /* 对应数据库中的 COUNT() 函数 */
    public static int Count();
    public static long LongCount();

    /* 对应数据库中的 MAX(exp) 函数 */
    public static TResult Max<TResult>(TResult p);
    /* 对应数据库中的 MIN(exp) 函数 */
    public static TResult Min<TResult>(TResult p);

    /* 对应数据库中的 SUM(exp) 函数 */
    public static int Sum(int p);
    public static int? Sum(int? p);
    public static long Sum(long p);
    public static long? Sum(long? p);
    public static decimal Sum(decimal p);
    public static decimal? Sum(decimal? p);
    public static double Sum(double p);
    public static double? Sum(double? p);
    public static float Sum(float p);
    public static float? Sum(float? p);

    /* 对应数据库中的 AVG(exp) 函数 */
    public static double Average(int p);
    public static double? Average(int? p);
    public static double Average(long p);
    public static double? Average(long? p);
    public static decimal Average(decimal p);
    public static decimal? Average(decimal? p);
    public static double Average(double p);
    public static double? Average(double? p);
    public static float Average(float p);
    public static float? Average(float? p);

    /* 求两个时间的年差,对应 SqlServer 的 DATEDIFF(YEAR,dateTime1,dateTime2) */
    public static int? DiffYears(DateTime? dateTime1, DateTime? dateTime2);

    /* 求两个时间的月差,对应 SqlServer 的 DATEDIFF(MONTH,dateTime1,dateTime2) */
    public static int? DiffMonths(DateTime? dateTime1, DateTime? dateTime2);

    /* 求两个时间的日差,对应 SqlServer 的 DATEDIFF(DAY,dateTime1,dateTime2) */
    public static int? DiffDays(DateTime? dateTime1, DateTime? ddateTime2);

    /* 求两个时间的时差,对应 SqlServer 的 DATEDIFF(HOUR,dateTime1,dateTime2) */
    public static int? DiffHours(DateTime? dateTime1, DateTime? dateTime2);

    /* 求两个时间的分钟差,对应 SqlServer 的 DATEDIFF(MINUTE,dateTime1,dateTime2) */
    public static int? DiffMinutes(DateTime? dateTime1, DateTime? dateTime2);

    /* 求两个时间的秒差,对应 SqlServer 的 DATEDIFF(SECOND,dateTime1,dateTime2) */
    public static int? DiffSeconds(DateTime? dateTime1, DateTime? dateTime2);

    /* 求两个时间的毫秒差,对应 SqlServer 的 DATEDIFF(DATEDIFF,dateTime1,dateTime2) */
    public static int? DiffMilliseconds(DateTime? dateTime1, DateTime? dateTime2);

    /* 求两个时间的微毫秒差,对应 SqlServer 的 DATEDIFF(MICROSECOND,dateTime1,dateTime2) */
    public static int? DiffMicroseconds(DateTime? dateTime1, DateTime? dateTime2);
}