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

Commit 6684dfa

Browse files
committed
Add Select Into overloads
1 parent ce47406 commit 6684dfa

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

src/ServiceStack.OrmLite/Expressions/ReadConnectionExtensions.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,14 @@ public static List<T> Select<T>(this IDbConnection dbConn, SqlExpression<T> expr
114114
return dbConn.Exec(dbCmd => dbCmd.Select(expression));
115115
}
116116

117+
/// <summary>
118+
/// Project results from a number of joined tables into a different model
119+
/// </summary>
120+
public static List<Into> Select<Into, From>(this IDbConnection dbConn, SqlExpression<From> expression)
121+
{
122+
return dbConn.Exec(dbCmd => dbCmd.Select<Into, From>(expression));
123+
}
124+
117125
/// <summary>
118126
/// Project results from a number of joined tables into a different model
119127
/// </summary>

src/ServiceStack.OrmLite/Expressions/ReadExtensions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ internal static List<Into> Select<Into, From>(this IDbCommand dbCmd, Func<SqlExp
2929
return dbCmd.ExprConvertToList<Into>(sql);
3030
}
3131

32+
internal static List<Into> Select<Into, From>(this IDbCommand dbCmd, SqlExpression<From> expression)
33+
{
34+
string sql = expression.SelectInto<Into>();
35+
return dbCmd.ExprConvertToList<Into>(sql);
36+
}
37+
3238
internal static List<T> Select<T>(this IDbCommand dbCmd, SqlExpression<T> expression)
3339
{
3440
string sql = expression.SelectInto<T>();

src/ServiceStack.OrmLite/Expressions/SqlExpression.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,13 @@ public virtual SqlExpression<T> Where()
145145

146146
public virtual SqlExpression<T> Where(string sqlFilter, params object[] filterParams)
147147
{
148-
whereExpression = !string.IsNullOrEmpty(sqlFilter) ? sqlFilter.SqlFmt(filterParams) : string.Empty;
149-
if (!string.IsNullOrEmpty(whereExpression)) whereExpression = (WhereStatementWithoutWhereString ? "" : "WHERE ") + whereExpression;
148+
whereExpression = !string.IsNullOrEmpty(sqlFilter)
149+
? sqlFilter.SqlFmt(filterParams)
150+
: string.Empty;
151+
152+
if (!string.IsNullOrEmpty(whereExpression))
153+
whereExpression = (WhereStatementWithoutWhereString ? "" : "WHERE ") + whereExpression;
154+
150155
return this;
151156
}
152157

@@ -1041,17 +1046,15 @@ protected virtual string BindOperant(ExpressionType e)
10411046

10421047
protected virtual string GetQuotedColumnName(string memberName)
10431048
{
1044-
10451049
if (useFieldName)
10461050
{
1047-
FieldDefinition fd = modelDef.FieldDefinitions.FirstOrDefault(x => x.Name == memberName);
1048-
string fn = fd != default(FieldDefinition) ? fd.FieldName : memberName;
1051+
var fd = modelDef.FieldDefinitions.FirstOrDefault(x => x.Name == memberName);
1052+
var fn = fd != null
1053+
? fd.FieldName
1054+
: memberName;
10491055
return DialectProvider.GetQuotedColumnName(fn);
10501056
}
1051-
else
1052-
{
1053-
return memberName;
1054-
}
1057+
return memberName;
10551058
}
10561059

10571060
protected string RemoveQuoteFromAlias(string exp)

0 commit comments

Comments
 (0)