Skip to content

Commit f20f356

Browse files
committed
Thread safety is too hard 😄
1 parent 276a1c8 commit f20f356

2 files changed

Lines changed: 7 additions & 10 deletions

File tree

src/Sql/Reflection/TableInfo.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace Belin.Sql.Reflection;
22

3-
using System.Collections.Concurrent;
3+
using System.Collections.Frozen;
44
using System.ComponentModel.DataAnnotations.Schema;
55
using System.Reflection;
66

@@ -39,17 +39,14 @@ public sealed class TableInfo {
3939
/// </summary>
4040
/// <param name="type">The type information providing the table metadata.</param>
4141
public TableInfo(Type type) {
42-
var properties =
42+
var table = type.GetCustomAttribute<TableAttribute>();
43+
var columns =
4344
from property in type.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public)
4445
where !property.IsDefined(typeof(NotMappedAttribute)) && ((property.CanRead && property.CanWrite) || property.IsDefined(typeof(ColumnAttribute)))
45-
select property;
46-
47-
var table = type.GetCustomAttribute<TableAttribute>();
48-
var columns = new ConcurrentDictionary<string, ColumnInfo>();
49-
foreach (var property in properties) columns.TryAdd(property.Name, new ColumnInfo(property));
46+
select new ColumnInfo(property);
5047

51-
Columns = columns;
52-
IdentityColumn = columns.Values.SingleOrDefault(column => column.IsIdentity) ?? (columns.TryGetValue("Id", out var column) ? column : null);
48+
Columns = columns.ToFrozenDictionary(column => column.Name);
49+
IdentityColumn = Columns.Values.SingleOrDefault(column => column.IsIdentity) ?? (Columns.TryGetValue("Id", out var column) ? column : null);
5350
Name = table?.Name ?? type.Name;
5451
Schema = table?.Schema;
5552
Type = type;

test/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[assembly: Parallelize(Scope = ExecutionScope.MethodLevel)]
1+
[assembly: Parallelize(Scope = ExecutionScope.ClassLevel)]

0 commit comments

Comments
 (0)