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

Commit cff91a5

Browse files
committed
Relax Generic expression constraint on db.Scalar/q.Select
1 parent dea89fa commit cff91a5

File tree

5 files changed

+13
-15
lines changed

5 files changed

+13
-15
lines changed

src/ServiceStack.OrmLite/Async/ReadExpressionCommandExtensionsAsync.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ internal static Task<T> SingleAsync<T>(this IDbCommand dbCmd, SqlExpression<T> e
8484
return dbCmd.ExprConvertToAsync<T>(sql, expression.Params, token);
8585
}
8686

87-
public static Task<TKey> ScalarAsync<T, TKey>(this IDbCommand dbCmd, Expression<Func<T, TKey>> field, CancellationToken token)
87+
public static Task<TKey> ScalarAsync<T, TKey>(this IDbCommand dbCmd, Expression<Func<T, object>> field, CancellationToken token)
8888
{
8989
var q = dbCmd.GetDialectProvider().SqlExpression<T>();
9090
q.Select(field);
@@ -93,7 +93,7 @@ public static Task<TKey> ScalarAsync<T, TKey>(this IDbCommand dbCmd, Expression<
9393
}
9494

9595
internal static Task<TKey> ScalarAsync<T, TKey>(this IDbCommand dbCmd,
96-
Expression<Func<T, TKey>> field, Expression<Func<T, bool>> predicate, CancellationToken token)
96+
Expression<Func<T, object>> field, Expression<Func<T, bool>> predicate, CancellationToken token)
9797
{
9898
var q = dbCmd.GetDialectProvider().SqlExpression<T>();
9999
q.Select(field).Where(predicate);

src/ServiceStack.OrmLite/Expressions/ReadExpressionCommandExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public static TKey Scalar<T, TKey>(this IDbCommand dbCmd, SqlExpression<T> expre
102102
return dbCmd.Scalar<TKey>(sql, expression.Params);
103103
}
104104

105-
public static TKey Scalar<T, TKey>(this IDbCommand dbCmd, Expression<Func<T, TKey>> field)
105+
public static TKey Scalar<T, TKey>(this IDbCommand dbCmd, Expression<Func<T, object>> field)
106106
{
107107
var q = dbCmd.GetDialectProvider().SqlExpression<T>();
108108
q.Select(field);
@@ -111,7 +111,7 @@ public static TKey Scalar<T, TKey>(this IDbCommand dbCmd, Expression<Func<T, TKe
111111
}
112112

113113
internal static TKey Scalar<T, TKey>(this IDbCommand dbCmd,
114-
Expression<Func<T, TKey>> field, Expression<Func<T, bool>> predicate)
114+
Expression<Func<T, object>> field, Expression<Func<T, bool>> predicate)
115115
{
116116
var q = dbCmd.GetDialectProvider().SqlExpression<T>();
117117
q.Select(field).Where(predicate);

src/ServiceStack.OrmLite/Expressions/SqlExpression.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,8 @@ public virtual SqlExpression<T> Select(string[] fields)
190190
/// <param name='fields'>
191191
/// x=> x.SomeProperty1 or x=> new{ x.SomeProperty1, x.SomeProperty2}
192192
/// </param>
193-
/// <typeparam name='TKey'>
194-
/// objectWithProperties
195193
/// </typeparam>
196-
public virtual SqlExpression<T> Select<TKey>(Expression<Func<T, TKey>> fields)
194+
public virtual SqlExpression<T> Select(Expression<Func<T, object>> fields)
197195
{
198196
sep = string.Empty;
199197
useFieldName = true;

src/ServiceStack.OrmLite/OrmLiteReadExpressionsApi.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,19 +188,19 @@ public static T Single<T>(this IDbConnection dbConn, ISqlExpression expression)
188188
/// Returns a scalar result from using an SqlExpression lambda. E.g:
189189
/// <para>db.Scalar&lt;Person, int&gt;(x =&gt; Sql.Max(x.Age))</para>
190190
/// </summary>
191-
public static TKey Scalar<T, TKey>(this IDbConnection dbConn, Expression<Func<T, TKey>> field)
191+
public static TKey Scalar<T, TKey>(this IDbConnection dbConn, Expression<Func<T, object>> field)
192192
{
193-
return dbConn.Exec(dbCmd => dbCmd.Scalar(field));
193+
return dbConn.Exec(dbCmd => dbCmd.Scalar<T, TKey>(field));
194194
}
195195

196196
/// <summary>
197197
/// Returns a scalar result from using an SqlExpression lambda. E.g:
198198
/// <para>db.Scalar&lt;Person, int&gt;(x =&gt; Sql.Max(x.Age), , x =&gt; x.Age &lt; 50)</para>
199199
/// </summary>
200200
public static TKey Scalar<T, TKey>(this IDbConnection dbConn,
201-
Expression<Func<T, TKey>> field, Expression<Func<T, bool>> predicate)
201+
Expression<Func<T, object>> field, Expression<Func<T, bool>> predicate)
202202
{
203-
return dbConn.Exec(dbCmd => dbCmd.Scalar(field, predicate));
203+
return dbConn.Exec(dbCmd => dbCmd.Scalar<T, TKey>(field, predicate));
204204
}
205205

206206
/// <summary>

src/ServiceStack.OrmLite/OrmLiteReadExpressionsApiAsync.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,19 +109,19 @@ public static class OrmLiteReadExpressionsApiAsync
109109
/// Returns a scalar result from using an SqlExpression lambda. E.g:
110110
/// <para>db.Scalar&lt;Person, int&gt;(x =&gt; Sql.Max(x.Age))</para>
111111
/// </summary>
112-
public static Task<TKey> ScalarAsync<T, TKey>(this IDbConnection dbConn, Expression<Func<T, TKey>> field, CancellationToken token = default(CancellationToken))
112+
public static Task<TKey> ScalarAsync<T, TKey>(this IDbConnection dbConn, Expression<Func<T, object>> field, CancellationToken token = default(CancellationToken))
113113
{
114-
return dbConn.Exec(dbCmd => dbCmd.ScalarAsync(field, token));
114+
return dbConn.Exec(dbCmd => dbCmd.ScalarAsync<T, TKey>(field, token));
115115
}
116116

117117
/// <summary>
118118
/// Returns a scalar result from using an SqlExpression lambda. E.g:
119119
/// <para>db.Scalar&lt;Person, int&gt;(x =&gt; Sql.Max(x.Age), , x =&gt; x.Age &lt; 50)</para>
120120
/// </summary>
121121
public static Task<TKey> ScalarAsync<T, TKey>(this IDbConnection dbConn,
122-
Expression<Func<T, TKey>> field, Expression<Func<T, bool>> predicate, CancellationToken token = default(CancellationToken))
122+
Expression<Func<T, object>> field, Expression<Func<T, bool>> predicate, CancellationToken token = default(CancellationToken))
123123
{
124-
return dbConn.Exec(dbCmd => dbCmd.ScalarAsync(field, predicate, token));
124+
return dbConn.Exec(dbCmd => dbCmd.ScalarAsync<T, TKey>(field, predicate, token));
125125
}
126126

127127
/// <summary>

0 commit comments

Comments
 (0)