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

Commit 707968d

Browse files
committed
Change Load APIs include to include .GetFieldNames() expression to maintain consistent features
1 parent 3370cf3 commit 707968d

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

src/ServiceStack.OrmLite/OrmLiteReadApi.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,9 +597,9 @@ public static T LoadSingleById<T>(this IDbConnection dbConn, object idValue, str
597597
/// Returns the first result with all its references loaded, using a primary key id. E.g:
598598
/// <para>db.LoadSingleById&lt;Person&gt;(1, include = x => new{ x.Address })</para>
599599
/// </summary>
600-
public static T LoadSingleById<T>(this IDbConnection dbConn, object idValue, Func<T,object> include)
600+
public static T LoadSingleById<T>(this IDbConnection dbConn, object idValue, Expression<Func<T, object>> include)
601601
{
602-
return dbConn.Exec(dbCmd => dbCmd.LoadSingleById<T>(idValue, include(typeof(T).CreateInstance<T>()).GetType().AllAnonFields() ));
602+
return dbConn.Exec(dbCmd => dbCmd.LoadSingleById<T>(idValue, include.GetFieldNames() ));
603603
}
604604

605605
/// <summary>

src/ServiceStack.OrmLite/OrmLiteReadApiAsync.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -524,11 +524,11 @@ public static Task<T> LoadSingleByIdAsync<T>(this IDbConnection dbConn, object i
524524

525525
/// <summary>
526526
/// Returns the first result with all its references loaded, using a primary key id. E.g:
527-
/// <para>db.LoadSingleById&lt;Person&gt;(1, include = x => new{ x.Address })</para>
527+
/// <para>db.LoadSingleById&lt;Person&gt;(1, include = x => new { x.Address })</para>
528528
/// </summary>
529-
public static Task<T> LoadSingleByIdAsync<T>(this IDbConnection dbConn, object idValue, Func<T, object> include, CancellationToken token = default(CancellationToken))
529+
public static Task<T> LoadSingleByIdAsync<T>(this IDbConnection dbConn, object idValue, Expression<Func<T, object>> include, CancellationToken token = default(CancellationToken))
530530
{
531-
return dbConn.Exec(dbCmd => dbCmd.LoadSingleByIdAsync<T>(idValue, include(typeof(T).CreateInstance<T>()).GetType().AllAnonFields(), token));
531+
return dbConn.Exec(dbCmd => dbCmd.LoadSingleByIdAsync<T>(idValue, include.GetFieldNames(), token));
532532
}
533533

534534
/// <summary>

src/ServiceStack.OrmLite/OrmLiteReadExpressionsApi.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,9 @@ public static List<T> LoadSelect<T>(this IDbConnection dbConn, Expression<Func<T
256256
/// Returns results with references from using a LINQ Expression. E.g:
257257
/// <para>db.LoadSelect&lt;Person&gt;(x =&gt; x.Age &gt; 40, include: x => new { x.PrimaryAddress })</para>
258258
/// </summary>
259-
public static List<T> LoadSelect<T>(this IDbConnection dbConn, Expression<Func<T, bool>> predicate, Func<T, object> include)
259+
public static List<T> LoadSelect<T>(this IDbConnection dbConn, Expression<Func<T, bool>> predicate, Expression<Func<T, object>> include)
260260
{
261-
return dbConn.Exec(dbCmd => dbCmd.LoadSelect(predicate, include(typeof(T).CreateInstance<T>()).GetType().AllAnonFields()));
261+
return dbConn.Exec(dbCmd => dbCmd.LoadSelect(predicate, include.GetFieldNames()));
262262
}
263263

264264
/// <summary>
@@ -274,9 +274,9 @@ public static List<T> LoadSelect<T>(this IDbConnection dbConn, SqlExpression<T>
274274
/// Returns results with references from using an SqlExpression lambda. E.g:
275275
/// <para>db.LoadSelect(db.From&lt;Person&gt;().Where(x =&gt; x.Age &gt; 40), include: x => new { x.PrimaryAddress })</para>
276276
/// </summary>
277-
public static List<T> LoadSelect<T>(this IDbConnection dbConn, SqlExpression<T> expression, Func<T, object> include)
277+
public static List<T> LoadSelect<T>(this IDbConnection dbConn, SqlExpression<T> expression, Expression<Func<T, object>> include)
278278
{
279-
return dbConn.Exec(dbCmd => dbCmd.LoadSelect(expression, include(typeof(T).CreateInstance<T>()).GetType().AllAnonFields()));
279+
return dbConn.Exec(dbCmd => dbCmd.LoadSelect(expression, include.GetFieldNames()));
280280
}
281281

282282
/// <summary>
@@ -290,9 +290,9 @@ public static List<Into> LoadSelect<Into, From>(this IDbConnection dbConn, SqlEx
290290
/// <summary>
291291
/// Project results with references from a number of joined tables into a different model
292292
/// </summary>
293-
public static List<Into> LoadSelect<Into, From>(this IDbConnection dbConn, SqlExpression<From> expression, Func<Into, object> include)
293+
public static List<Into> LoadSelect<Into, From>(this IDbConnection dbConn, SqlExpression<From> expression, Expression<Func<Into, object>> include)
294294
{
295-
return dbConn.Exec(dbCmd => dbCmd.LoadSelect<Into, From>(expression, include(typeof(Into).CreateInstance<Into>()).GetType().AllAnonFields()));
295+
return dbConn.Exec(dbCmd => dbCmd.LoadSelect<Into, From>(expression, include.GetFieldNames()));
296296
}
297297
}
298298
}

0 commit comments

Comments
 (0)