Skip to content

Commit 5649b2a

Browse files
author
Wood, Roger C
committed
Adding PI cache for Update.
1 parent 1d049d3 commit 5649b2a

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

QueryBuilder/Query.Update.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Concurrent;
23
using System.Collections.Generic;
34
using System.Linq;
45
using System.Reflection;
@@ -15,33 +16,32 @@ public Query AsUpdate(object data)
1516
return AsUpdate(dictionary);
1617
}
1718

18-
19-
private static Dictionary<Type, List<PropertyInfo>> CacheDictionaryProperties = new Dictionary<Type, List<PropertyInfo>>();
20-
19+
private static readonly ConcurrentDictionary<Type, PropertyInfo[]> CacheDictionaryProperties = new ConcurrentDictionary<Type, PropertyInfo[]>();
2120

2221
private Dictionary<string, object> BuildDictionaryOnUpdate(object data)
2322
{
24-
2523
var dictionary = new Dictionary<string, object>();
26-
var props = data.GetType().GetRuntimeProperties();
24+
var props = CacheDictionaryProperties.GetOrAdd(data.GetType(), type => type.GetRuntimeProperties().ToArray());
2725

2826
foreach (PropertyInfo property in props)
2927
{
30-
if (property.GetCustomAttribute(typeof(IgnoreAttribute)) != null){
28+
if (property.GetCustomAttribute(typeof(IgnoreAttribute)) != null)
29+
{
3130
continue;
3231
}
3332

3433
var value = property.GetValue(data);
3534

3635
var colAttr = property.GetCustomAttribute(typeof(ColumnAttribute)) as ColumnAttribute;
3736
var name = colAttr?.Name ?? property.Name;
38-
if(colAttr != null)
37+
if (colAttr != null)
3938
{
40-
if((colAttr as KeyAttribute) != null)
39+
if ((colAttr as KeyAttribute) != null)
4140
{
4241
this.Where(name, value);
4342
}
44-
}
43+
}
44+
4545
dictionary.Add(name, value);
4646
}
4747

QueryBuilder/QueryBuilder.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
<Description>A powerful Dynamic Sql Query Builder supporting Sql Server, MySql, PostgreSql and Firebird</Description>
88
<Authors>Ahmad Moussawi</Authors>
99
<Copyright>Copyright (c) 2017 Ahmad Moussawi</Copyright>
10-
<TargetFrameworks>netstandard1.0;net45</TargetFrameworks>
10+
<TargetFrameworks>net45;netstandard1.1</TargetFrameworks>
1111
<RootNamespace>SqlKata</RootNamespace>
1212
</PropertyGroup>
13+
<ItemGroup>
14+
<PackageReference Include="System.Collections.Concurrent" Version="4.3.0" />
15+
</ItemGroup>
1316
</Project>

0 commit comments

Comments
 (0)