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

Commit d979c70

Browse files
committed
Call UpdateFilter on anonymous type
1 parent 02ff1d2 commit d979c70

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

src/ServiceStack.OrmLite/Async/WriteExpressionCommandExtensionsAsync.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ internal static Task<int> UpdateAsync<T>(this IDbCommand dbCmd, T item, Expressi
111111

112112
internal static Task<int> UpdateAsync<T>(this IDbCommand dbCmd, object updateOnly, Expression<Func<T, bool>> where, Action<IDbCommand> commandFilter, CancellationToken token)
113113
{
114+
OrmLiteConfig.UpdateFilter?.Invoke(dbCmd, updateOnly);
115+
114116
var q = dbCmd.GetDialectProvider().SqlExpression<T>();
115117
var whereSql = q.Where(where).WhereExpression;
116118
q.CopyParamsTo(dbCmd);

src/ServiceStack.OrmLite/Expressions/WriteExpressionCommandExtensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ public static int Update<T>(this IDbCommand dbCmd, T item, Expression<Func<T, bo
155155

156156
public static int Update<T>(this IDbCommand dbCmd, object updateOnly, Expression<Func<T, bool>> where = null, Action<IDbCommand> commandFilter = null)
157157
{
158+
OrmLiteConfig.UpdateFilter?.Invoke(dbCmd, updateOnly);
159+
158160
var q = dbCmd.GetDialectProvider().SqlExpression<T>();
159161
var whereSql = q.Where(where).WhereExpression;
160162
q.CopyParamsTo(dbCmd);

tests/ServiceStack.OrmLite.Tests/OrmLiteFiltersTests.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,5 +183,28 @@ public void Exceptions_in_filters_prevents_insert_and_update()
183183
OrmLiteConfig.InsertFilter = OrmLiteConfig.UpdateFilter = null;
184184
}
185185

186+
[Test]
187+
public void Does_call_UpdateFilter_on_anonymous_Type()
188+
{
189+
var called = false;
190+
OrmLiteConfig.UpdateFilter = (dbCmd, row) => { called = true; };
191+
192+
using (var db = OpenDbConnection())
193+
{
194+
db.DropAndCreateTable<AuditTableA>();
195+
196+
var a = new AuditTableA();
197+
var id = db.Insert(a, selectIdentity:true);
198+
199+
db.Update<AuditTableA>(new { ModifiedBy = "Updated" }, where: x => x.Id == id);
200+
201+
Assert.That(db.SingleById<AuditTableA>(id).ModifiedBy, Is.EqualTo("Updated"));
202+
203+
Assert.That(called);
204+
}
205+
206+
OrmLiteConfig.UpdateFilter = null;
207+
}
208+
186209
}
187210
}

0 commit comments

Comments
 (0)