@@ -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>Person<());
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<Person>(new Dictionary<string,object< { {"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<Person> (new Dictionary<string,object< { {"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<Person>(new Dictionary<string,object< { {"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<Person>(new Dictionary<string,object< { {"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<Person>(new Dictionary<string,object< { {"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<Person>(new Dictionary<string,object< { {"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