Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 3677171

Browse files
committed
Add string overloads for Sql.Aggregate operators so they can be used as-is in Select expressions
1 parent 6124b8b commit 3677171

File tree

1 file changed

+71
-40
lines changed
  • src/ServiceStack.OrmLite/Expressions

1 file changed

+71
-40
lines changed
Lines changed: 71 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
using System.Collections;
22
using System.Linq;
3-
using System.Collections.Generic;
4-
5-
namespace ServiceStack.OrmLite
6-
{
7-
public static class Sql
8-
{
3+
using System.Collections.Generic;
4+
5+
namespace ServiceStack.OrmLite
6+
{
7+
public static class Sql
8+
{
99
public static bool In<T, TItem>(T value, params TItem[] list)
1010
{
1111
return value != null && Flatten(list).Any(obj => obj.ToString() == value.ToString());
1212
}
1313

14-
public static List<object> Flatten(IEnumerable list)
14+
public static List<object> Flatten(IEnumerable list)
1515
{
1616
var ret = new List<object>();
17-
if (list == null) return ret;
17+
if (list == null) return ret;
1818

1919
foreach (var item in list)
2020
{
@@ -33,35 +33,66 @@ public static List<object> Flatten(IEnumerable list)
3333
return ret;
3434
}
3535

36-
public static string Desc<T>(T value)
37-
{
38-
return value==null? "": value.ToString() + " DESC";
39-
}
40-
41-
public static string As<T>( T value, object asValue) {
42-
return value==null? "": string.Format("{0} AS {1}", value.ToString(), asValue);
43-
}
44-
45-
public static T Sum<T>( T value) {
46-
return value;
47-
}
48-
49-
public static T Count<T>( T value) {
50-
return value;
51-
}
52-
53-
public static T Min<T>( T value) {
54-
return value;
55-
}
56-
57-
public static T Max<T>( T value) {
58-
return value;
59-
}
60-
61-
public static T Avg<T>( T value) {
62-
return value;
63-
}
64-
}
65-
66-
}
67-
36+
public static string Desc<T>(T value)
37+
{
38+
return value == null ? "" : value.ToString() + " DESC";
39+
}
40+
41+
public static string As<T>(T value, object asValue)
42+
{
43+
return value == null ? "" : string.Format("{0} AS {1}", value.ToString(), asValue);
44+
}
45+
46+
public static T Sum<T>(T value)
47+
{
48+
return value;
49+
}
50+
51+
public static string Sum(string value)
52+
{
53+
return "SUM({0})".Fmt(value);
54+
}
55+
56+
public static T Count<T>(T value)
57+
{
58+
return value;
59+
}
60+
61+
public static string Count(string value)
62+
{
63+
return "COUNT({0})".Fmt(value);
64+
}
65+
66+
public static T Min<T>(T value)
67+
{
68+
return value;
69+
}
70+
71+
public static string Min(string value)
72+
{
73+
return "MIN({0})".Fmt(value);
74+
}
75+
76+
public static T Max<T>(T value)
77+
{
78+
return value;
79+
}
80+
81+
public static string Max(string value)
82+
{
83+
return "MAX({0})".Fmt(value);
84+
}
85+
86+
public static T Avg<T>(T value)
87+
{
88+
return value;
89+
}
90+
91+
public static string Avg(string value)
92+
{
93+
return "AVG({0})".Fmt(value);
94+
}
95+
}
96+
97+
}
98+

0 commit comments

Comments
 (0)