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

Commit a8adffa

Browse files
committed
Add OrmLiteConfig.PopulatedObjectFilter
1 parent e8e3f1a commit a8adffa

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/ServiceStack.OrmLite/OrmLiteConfig.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ public static IOrmLiteExecFilter ExecFilter
183183

184184
public static Func<FieldDefinition, object> OnDbNullFilter { get; set; }
185185

186+
public static Action<object> PopulatedObjectFilter { get; set; }
187+
186188
public static Action<IDbCommand, Exception> ExceptionFilter { get; set; }
187189

188190
public static bool ThrowOnError { get; set; }

src/ServiceStack.OrmLite/OrmLiteWriteCommandExtensions.cs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,8 @@ public static T PopulateWithSqlReader<T>(this T objWithProperties,
334334
{
335335
values = PopulateValues(reader, values, dialectProvider);
336336

337+
var dbNullFilter = OrmLiteConfig.OnDbNullFilter;
338+
337339
foreach (var fieldCache in indexCache)
338340
{
339341
try
@@ -345,12 +347,9 @@ public static T PopulateWithSqlReader<T>(this T objWithProperties,
345347
if (values != null && values[index] == DBNull.Value)
346348
{
347349
var value = fieldDef.IsNullable ? null : fieldDef.FieldTypeDefaultValue;
348-
if (OrmLiteConfig.OnDbNullFilter != null)
349-
{
350-
var useValue = OrmLiteConfig.OnDbNullFilter(fieldDef);
351-
if (useValue != null)
352-
value = useValue;
353-
}
350+
var useValue = dbNullFilter?.Invoke(fieldDef);
351+
if (useValue != null)
352+
value = useValue;
354353

355354
fieldDef.SetValueFn(objWithProperties, value);
356355
}
@@ -361,12 +360,9 @@ public static T PopulateWithSqlReader<T>(this T objWithProperties,
361360
{
362361
if (!fieldDef.IsNullable)
363362
value = fieldDef.FieldTypeDefaultValue;
364-
if (OrmLiteConfig.OnDbNullFilter != null)
365-
{
366-
var useValue = OrmLiteConfig.OnDbNullFilter(fieldDef);
367-
if (useValue != null)
368-
value = useValue;
369-
}
363+
var useValue = dbNullFilter?.Invoke(fieldDef);
364+
if (useValue != null)
365+
value = useValue;
370366
fieldDef.SetValueFn(objWithProperties, value);
371367
}
372368
else
@@ -381,6 +377,8 @@ public static T PopulateWithSqlReader<T>(this T objWithProperties,
381377
OrmLiteUtils.HandleException(ex);
382378
}
383379
}
380+
381+
OrmLiteConfig.PopulatedObjectFilter?.Invoke(objWithProperties);
384382

385383
return objWithProperties;
386384
}

0 commit comments

Comments
 (0)