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

Commit a99e7d8

Browse files
committed
Change LoadSelect to support LoadSelect<Into,From>
1 parent c4b30d2 commit a99e7d8

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

src/ServiceStack.OrmLite/Expressions/ReadConnectionExtensions.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,5 +246,12 @@ public static List<T> LoadSelect<T>(this IDbConnection dbConn, SqlExpression<T>
246246
return dbConn.Exec(dbCmd => dbCmd.LoadSelect(expression));
247247
}
248248

249+
/// <summary>
250+
/// Project results with references from a number of joined tables into a different model
251+
/// </summary>
252+
public static List<Into> LoadSelect<Into, From>(this IDbConnection dbConn, SqlExpression<From> expression)
253+
{
254+
return dbConn.Exec(dbCmd => dbCmd.LoadSelect<Into, From>(expression));
255+
}
249256
}
250257
}

src/ServiceStack.OrmLite/Expressions/ReadExtensions.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,23 @@ internal static List<T> LoadSelect<T>(this IDbCommand dbCmd, Func<SqlExpression<
120120
{
121121
var expr = OrmLiteConfig.DialectProvider.SqlExpression<T>();
122122
expr = expression(expr);
123-
return dbCmd.LoadListWithReferences(expr);
123+
return dbCmd.LoadListWithReferences<T, T>(expr);
124124
}
125125

126126
internal static List<T> LoadSelect<T>(this IDbCommand dbCmd, SqlExpression<T> expression = null)
127127
{
128-
return dbCmd.LoadListWithReferences(expression);
128+
return dbCmd.LoadListWithReferences<T, T>(expression);
129+
}
130+
131+
internal static List<Into> LoadSelect<Into, From>(this IDbCommand dbCmd, SqlExpression<From> expression)
132+
{
133+
return dbCmd.LoadListWithReferences<Into, From>(expression);
129134
}
130135

131136
internal static List<T> LoadSelect<T>(this IDbCommand dbCmd, Expression<Func<T, bool>> predicate)
132137
{
133138
var expr = OrmLiteConfig.DialectProvider.SqlExpression<T>().Where(predicate);
134-
return dbCmd.LoadListWithReferences(expr);
139+
return dbCmd.LoadListWithReferences<T, T>(expr);
135140
}
136141

137142
internal static T ExprConvertTo<T>(this IDataReader dataReader)

src/ServiceStack.OrmLite/OrmLiteReadExtensions.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -896,16 +896,16 @@ public static void LoadReferences<T>(this IDbCommand dbCmd, T instance)
896896
}
897897
}
898898

899-
internal static List<T> LoadListWithReferences<T>(this IDbCommand dbCmd, SqlExpression<T> expr = null)
899+
internal static List<Into> LoadListWithReferences<Into, From>(this IDbCommand dbCmd, SqlExpression<From> expr = null)
900900
{
901901
var dialectProvider = OrmLiteConfig.DialectProvider;
902902
if (expr == null)
903-
expr = dialectProvider.SqlExpression<T>();
903+
expr = dialectProvider.SqlExpression<From>();
904904

905-
var sql = expr.SelectInto<T>();
906-
var parentResults = dbCmd.ExprConvertToList<T>(sql);
905+
var sql = expr.SelectInto<Into>();
906+
var parentResults = dbCmd.ExprConvertToList<Into>(sql);
907907

908-
var modelDef = ModelDefinition<T>.Definition;
908+
var modelDef = ModelDefinition<Into>.Definition;
909909
var fieldDefs = modelDef.AllFieldDefinitionsArray.Where(x => x.IsReference);
910910

911911
expr.Select(dialectProvider.GetQuotedColumnName(modelDef.PrimaryKey));

0 commit comments

Comments
 (0)