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

Commit f3f7302

Browse files
committed
Rename instance UpdateOnly/Async APIs to avoid new C# compiler ambiguous errors
1 parent 9f1120b commit f3f7302

33 files changed

Lines changed: 260 additions & 264 deletions

src/ServiceStack.OrmLite/Async/WriteExpressionCommandExtensionsAsync.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace ServiceStack.OrmLite
1010
{
1111
internal static class WriteExpressionCommandExtensionsAsync
1212
{
13-
internal static Task<int> UpdateOnlyAsync<T>(this IDbCommand dbCmd, T model, SqlExpression<T> onlyFields, Action<IDbCommand> commandFilter, CancellationToken token)
13+
internal static Task<int> UpdateOnlyFieldsAsync<T>(this IDbCommand dbCmd, T model, SqlExpression<T> onlyFields, Action<IDbCommand> commandFilter, CancellationToken token)
1414
{
1515
OrmLiteUtils.AssertNotAnonType<T>();
1616

@@ -19,7 +19,7 @@ internal static Task<int> UpdateOnlyAsync<T>(this IDbCommand dbCmd, T model, Sql
1919
return dbCmd.ExecNonQueryAsync(token);
2020
}
2121

22-
internal static Task<int> UpdateOnlyAsync<T>(this IDbCommand dbCmd, T obj,
22+
internal static Task<int> UpdateOnlyFieldsAsync<T>(this IDbCommand dbCmd, T obj,
2323
Expression<Func<T, object>> onlyFields,
2424
Expression<Func<T, bool>> where,
2525
Action<IDbCommand> commandFilter,
@@ -33,10 +33,10 @@ internal static Task<int> UpdateOnlyAsync<T>(this IDbCommand dbCmd, T obj,
3333
var q = dbCmd.GetDialectProvider().SqlExpression<T>();
3434
q.Update(onlyFields);
3535
q.Where(where);
36-
return dbCmd.UpdateOnlyAsync(obj, q, commandFilter, token);
36+
return dbCmd.UpdateOnlyFieldsAsync(obj, q, commandFilter, token);
3737
}
3838

39-
internal static Task<int> UpdateOnlyAsync<T>(this IDbCommand dbCmd, T obj,
39+
internal static Task<int> UpdateOnlyFieldsAsync<T>(this IDbCommand dbCmd, T obj,
4040
string[] onlyFields,
4141
Expression<Func<T, bool>> where,
4242
Action<IDbCommand> commandFilter,
@@ -50,7 +50,7 @@ internal static Task<int> UpdateOnlyAsync<T>(this IDbCommand dbCmd, T obj,
5050
var q = dbCmd.GetDialectProvider().SqlExpression<T>();
5151
q.Update(onlyFields);
5252
q.Where(where);
53-
return dbCmd.UpdateOnlyAsync(obj, q, commandFilter, token);
53+
return dbCmd.UpdateOnlyFieldsAsync(obj, q, commandFilter, token);
5454
}
5555

5656
internal static Task<int> UpdateOnlyAsync<T>(this IDbCommand dbCmd,

src/ServiceStack.OrmLite/Expressions/WriteExpressionCommandExtensions.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace ServiceStack.OrmLite
1212
{
1313
internal static class WriteExpressionCommandExtensions
1414
{
15-
public static int UpdateOnly<T>(this IDbCommand dbCmd,
15+
public static int UpdateOnlyFields<T>(this IDbCommand dbCmd,
1616
T model,
1717
SqlExpression<T> onlyFields,
1818
Action<IDbCommand> commandFilter = null)
@@ -42,7 +42,7 @@ internal static void UpdateOnlySql<T>(this IDbCommand dbCmd, T model, SqlExpress
4242
dbCmd.CommandText += " " + onlyFields.WhereExpression;
4343
}
4444

45-
internal static int UpdateOnly<T>(this IDbCommand dbCmd, T obj,
45+
internal static int UpdateOnlyFields<T>(this IDbCommand dbCmd, T obj,
4646
Expression<Func<T, object>> onlyFields = null,
4747
Expression<Func<T, bool>> where = null,
4848
Action<IDbCommand> commandFilter = null)
@@ -55,10 +55,10 @@ internal static int UpdateOnly<T>(this IDbCommand dbCmd, T obj,
5555
var q = dbCmd.GetDialectProvider().SqlExpression<T>();
5656
q.Update(onlyFields);
5757
q.Where(where);
58-
return dbCmd.UpdateOnly(obj, q, commandFilter);
58+
return dbCmd.UpdateOnlyFields(obj, q, commandFilter);
5959
}
6060

61-
internal static int UpdateOnly<T>(this IDbCommand dbCmd, T obj,
61+
internal static int UpdateOnlyFields<T>(this IDbCommand dbCmd, T obj,
6262
string[] onlyFields = null,
6363
Expression<Func<T, bool>> where = null,
6464
Action<IDbCommand> commandFilter = null)
@@ -71,7 +71,7 @@ internal static int UpdateOnly<T>(this IDbCommand dbCmd, T obj,
7171
var q = dbCmd.GetDialectProvider().SqlExpression<T>();
7272
q.Update(onlyFields);
7373
q.Where(where);
74-
return dbCmd.UpdateOnly(obj, q, commandFilter);
74+
return dbCmd.UpdateOnlyFields(obj, q, commandFilter);
7575
}
7676

7777
internal static int UpdateOnly<T>(this IDbCommand dbCmd,

src/ServiceStack.OrmLite/Legacy/WriteExpressionCommandExtensionsAsyncLegacy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ internal static Task InsertOnlyAsync<T>(this IDbCommand dbCmd, T obj, Func<SqlEx
1919
[Obsolete("Use db.UpdateOnlyAsync(model, db.From<T>())")]
2020
internal static Task<int> UpdateOnlyAsync<T>(this IDbCommand dbCmd, T model, Func<SqlExpression<T>, SqlExpression<T>> onlyFields, CancellationToken token)
2121
{
22-
return dbCmd.UpdateOnlyAsync(model, onlyFields(dbCmd.GetDialectProvider().SqlExpression<T>()), null, token);
22+
return dbCmd.UpdateOnlyFieldsAsync(model, onlyFields(dbCmd.GetDialectProvider().SqlExpression<T>()), null, token);
2323
}
2424

2525
internal static Task<int> UpdateFmtAsync<T>(this IDbCommand dbCmd, string set, string where, CancellationToken token)

src/ServiceStack.OrmLite/Legacy/WriteExpressionCommandExtensionsLegacy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static void InsertOnly<T>(this IDbCommand dbCmd, T obj, Func<SqlExpressio
1616
[Obsolete("Use db.UpdateOnly(model, db.From<T>())")]
1717
public static int UpdateOnly<T>(this IDbCommand dbCmd, T model, Func<SqlExpression<T>, SqlExpression<T>> onlyFields)
1818
{
19-
return dbCmd.UpdateOnly(model, onlyFields(dbCmd.GetDialectProvider().SqlExpression<T>()));
19+
return dbCmd.UpdateOnlyFields(model, onlyFields(dbCmd.GetDialectProvider().SqlExpression<T>()));
2020
}
2121

2222
public static int UpdateFmt<T>(this IDbCommand dbCmd, string set = null, string where = null)

src/ServiceStack.OrmLite/OrmLiteWriteExpressionsApi.cs

Lines changed: 63 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,55 @@ public static class OrmLiteWriteExpressionsApi
1111
/// Use an SqlExpression to select which fields to update and construct the where expression, E.g:
1212
///
1313
/// var q = db.From&gt;Person&lt;());
14-
/// db.UpdateOnly(new Person { FirstName = "JJ" }, q.Update(p => p.FirstName).Where(x => x.FirstName == "Jimi"));
14+
/// db.UpdateOnlyFields(new Person { FirstName = "JJ" }, q.Update(p => p.FirstName).Where(x => x.FirstName == "Jimi"));
1515
/// UPDATE "Person" SET "FirstName" = 'JJ' WHERE ("FirstName" = 'Jimi')
1616
///
1717
/// What's not in the update expression doesn't get updated. No where expression updates all rows. E.g:
1818
///
19-
/// db.UpdateOnly(new Person { FirstName = "JJ", LastName = "Hendo" }, ev.Update(p => p.FirstName));
19+
/// db.UpdateOnlyFields(new Person { FirstName = "JJ", LastName = "Hendo" }, ev.Update(p => p.FirstName));
2020
/// UPDATE "Person" SET "FirstName" = 'JJ'
2121
/// </summary>
22-
public static int UpdateOnly<T>(this IDbConnection dbConn, T model, SqlExpression<T> onlyFields, Action<IDbCommand> commandFilter = null)
22+
public static int UpdateOnlyFields<T>(this IDbConnection dbConn,
23+
T model, SqlExpression<T> onlyFields,
24+
Action<IDbCommand> commandFilter = null)
25+
{
26+
return dbConn.Exec(dbCmd => dbCmd.UpdateOnlyFields(model, onlyFields, commandFilter));
27+
}
28+
29+
/// <summary>
30+
/// Update record, updating only fields specified in updateOnly that matches the where condition (if any), E.g:
31+
///
32+
/// db.UpdateOnly(new Person { FirstName = "JJ" }, new[]{ "FirstName" }, p => p.LastName == "Hendrix");
33+
/// UPDATE "Person" SET "FirstName" = 'JJ' WHERE ("LastName" = 'Hendrix')
34+
/// </summary>
35+
public static int UpdateOnlyFields<T>(this IDbConnection dbConn,
36+
T obj,
37+
string[] onlyFields,
38+
Expression<Func<T, bool>> where = null,
39+
Action<IDbCommand> commandFilter = null)
40+
{
41+
return dbConn.Exec(dbCmd => dbCmd.UpdateOnlyFields(obj, onlyFields, where, commandFilter));
42+
}
43+
44+
/// <summary>
45+
/// Update record, updating only fields specified in updateOnly that matches the where condition (if any), E.g:
46+
///
47+
/// db.UpdateOnly(new Person { FirstName = "JJ" }, p => p.FirstName, p => p.LastName == "Hendrix");
48+
/// UPDATE "Person" SET "FirstName" = 'JJ' WHERE ("LastName" = 'Hendrix')
49+
///
50+
/// db.UpdateOnly(new Person { FirstName = "JJ" }, p => p.FirstName);
51+
/// UPDATE "Person" SET "FirstName" = 'JJ'
52+
///
53+
/// db.UpdateOnly(new Person { FirstName = "JJ", Age = 27 }, p => new { p.FirstName, p.Age );
54+
/// UPDATE "Person" SET "FirstName" = 'JJ', "Age" = 27
55+
/// </summary>
56+
public static int UpdateOnlyFields<T>(this IDbConnection dbConn,
57+
T obj,
58+
Expression<Func<T, object>> onlyFields = null,
59+
Expression<Func<T, bool>> where = null,
60+
Action<IDbCommand> commandFilter = null)
2361
{
24-
return dbConn.Exec(dbCmd => dbCmd.UpdateOnly(model, onlyFields, commandFilter));
62+
return dbConn.Exec(dbCmd => dbCmd.UpdateOnlyFields(obj, onlyFields, where, commandFilter));
2563
}
2664

2765
/// <summary>
@@ -72,37 +110,36 @@ public static int UpdateOnly<T>(this IDbConnection dbConn,
72110
}
73111

74112
/// <summary>
75-
/// Update record, updating only fields specified in updateOnly that matches the where condition (if any), E.g:
113+
/// Updates all values from Object Dictionary matching the where condition. E.g
76114
///
77-
/// db.UpdateOnly(new Person { FirstName = "JJ" }, p => p.FirstName, p => p.LastName == "Hendrix");
78-
/// UPDATE "Person" SET "FirstName" = 'JJ' WHERE ("LastName" = 'Hendrix')
79-
///
80-
/// db.UpdateOnly(new Person { FirstName = "JJ" }, p => p.FirstName);
81-
/// UPDATE "Person" SET "FirstName" = 'JJ'
82-
///
83-
/// db.UpdateOnly(new Person { FirstName = "JJ", Age = 27 }, p => new { p.FirstName, p.Age );
84-
/// UPDATE "Person" SET "FirstName" = 'JJ', "Age" = 27
115+
/// db.UpdateOnly&lt;Person&gt;(new Dictionary&lt;string,object&lt; { {"FirstName", "JJ"} }, where:p => p.FirstName == "Jimi");
116+
/// UPDATE "Person" SET "FirstName" = 'JJ' WHERE ("FirstName" = 'Jimi')
85117
/// </summary>
86-
public static int UpdateOnly<T>(this IDbConnection dbConn, T obj,
87-
Expression<Func<T, object>> onlyFields = null,
88-
Expression<Func<T, bool>> where = null,
89-
Action<IDbCommand> commandFilter = null)
118+
public static int UpdateOnly<T>(this IDbConnection dbConn, Dictionary<string, object> updateFields, Expression<Func<T, bool>> obj)
90119
{
91-
return dbConn.Exec(dbCmd => dbCmd.UpdateOnly(obj, onlyFields, where, commandFilter));
120+
return dbConn.Exec(dbCmd => dbCmd.UpdateOnly(updateFields, obj));
92121
}
93122

94123
/// <summary>
95-
/// Update record, updating only fields specified in updateOnly that matches the where condition (if any), E.g:
124+
/// Updates all values from Object Dictionary, Requires Id which is used as a Primary Key Filter. E.g
96125
///
97-
/// db.UpdateOnly(new Person { FirstName = "JJ" }, new[]{ "FirstName" }, p => p.LastName == "Hendrix");
98-
/// UPDATE "Person" SET "FirstName" = 'JJ' WHERE ("LastName" = 'Hendrix')
126+
/// db.UpdateOnly&lt;Person&gt;(new Dictionary&lt;string,object&lt; { {"Id", 1}, {"FirstName", "JJ"} });
127+
/// UPDATE "Person" SET "FirstName" = 'JJ' WHERE ("Id" = 1)
99128
/// </summary>
100-
public static int UpdateOnly<T>(this IDbConnection dbConn, T obj,
101-
string[] onlyFields,
102-
Expression<Func<T, bool>> where = null,
103-
Action<IDbCommand> commandFilter = null)
129+
public static int UpdateOnly<T>(this IDbConnection dbConn, Dictionary<string, object> updateFields, Action<IDbCommand> commandFilter = null)
130+
{
131+
return dbConn.Exec(dbCmd => dbCmd.UpdateOnly<T>(updateFields, commandFilter));
132+
}
133+
134+
/// <summary>
135+
/// Updates all values from Object Dictionary matching the where condition. E.g
136+
///
137+
/// db.UpdateOnly&lt;Person&gt;(new Dictionary&lt;string,object&lt; { {"FirstName", "JJ"} }, "FirstName == {0}", new[] { "Jimi" });
138+
/// UPDATE "Person" SET "FirstName" = 'JJ' WHERE ("FirstName" = 'Jimi')
139+
/// </summary>
140+
public static int UpdateOnly<T>(this IDbConnection dbConn, Dictionary<string, object> updateFields, string whereExpression, object[] whereParams, Action<IDbCommand> commandFilter = null)
104141
{
105-
return dbConn.Exec(dbCmd => dbCmd.UpdateOnly(obj, onlyFields, where, commandFilter));
142+
return dbConn.Exec(dbCmd => dbCmd.UpdateOnly<T>(updateFields, whereExpression, whereParams, commandFilter));
106143
}
107144

108145
/// <summary>
@@ -140,39 +177,6 @@ public static int UpdateAdd<T>(this IDbConnection dbConn,
140177
return dbConn.Exec(dbCmd => dbCmd.UpdateAdd(updateFields, q, commandFilter));
141178
}
142179

143-
/// <summary>
144-
/// Updates all values from Object Dictionary matching the where condition. E.g
145-
///
146-
/// db.UpdateOnly&lt;Person&gt;(new Dictionary&lt;string,object&lt; { {"FirstName", "JJ"} }, where:p => p.FirstName == "Jimi");
147-
/// UPDATE "Person" SET "FirstName" = 'JJ' WHERE ("FirstName" = 'Jimi')
148-
/// </summary>
149-
public static int UpdateOnly<T>(this IDbConnection dbConn, Dictionary<string, object> updateFields, Expression<Func<T, bool>> obj)
150-
{
151-
return dbConn.Exec(dbCmd => dbCmd.UpdateOnly(updateFields, obj));
152-
}
153-
154-
/// <summary>
155-
/// Updates all values from Object Dictionary, Requires Id which is used as a Primary Key Filter. E.g
156-
///
157-
/// db.UpdateOnly&lt;Person&gt;(new Dictionary&lt;string,object&lt; { {"Id", 1}, {"FirstName", "JJ"} });
158-
/// UPDATE "Person" SET "FirstName" = 'JJ' WHERE ("Id" = 1)
159-
/// </summary>
160-
public static int UpdateOnly<T>(this IDbConnection dbConn, Dictionary<string, object> updateFields, Action<IDbCommand> commandFilter = null)
161-
{
162-
return dbConn.Exec(dbCmd => dbCmd.UpdateOnly<T>(updateFields, commandFilter));
163-
}
164-
165-
/// <summary>
166-
/// Updates all values from Object Dictionary matching the where condition. E.g
167-
///
168-
/// db.UpdateOnly&lt;Person&gt;(new Dictionary&lt;string,object&lt; { {"FirstName", "JJ"} }, "FirstName == {0}", new[] { "Jimi" });
169-
/// UPDATE "Person" SET "FirstName" = 'JJ' WHERE ("FirstName" = 'Jimi')
170-
/// </summary>
171-
public static int UpdateOnly<T>(this IDbConnection dbConn, Dictionary<string, object> updateFields, string whereExpression, object[] whereParams, Action<IDbCommand> commandFilter = null)
172-
{
173-
return dbConn.Exec(dbCmd => dbCmd.UpdateOnly<T>(updateFields, whereExpression, whereParams, commandFilter));
174-
}
175-
176180
/// <summary>
177181
/// Updates all non-default values set on item matching the where condition (if any). E.g
178182
///

0 commit comments

Comments
 (0)