Skip to content

Commit eac7403

Browse files
committed
Code optimization
1 parent 32382f7 commit eac7403

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

src/Sql/Reflection/ColumnInfo.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ public sealed class ColumnInfo {
1111
/// <summary>
1212
/// The nullability context.
1313
/// </summary>
14-
[ThreadStatic]
15-
private static readonly NullabilityInfoContext nullabilityContext = new();
14+
private static readonly ThreadLocal<NullabilityInfoContext> nullabilityContext = new(() => new NullabilityInfoContext());
1615

1716
/// <summary>
1817
/// Value indicating whether the column can be read.
@@ -64,7 +63,7 @@ public ColumnInfo(PropertyInfo property) {
6463
var databaseGeneratedOption = property.GetCustomAttribute<DatabaseGeneratedAttribute>()?.DatabaseGeneratedOption ?? DatabaseGeneratedOption.None;
6564
IsComputed = databaseGeneratedOption != DatabaseGeneratedOption.None;
6665
IsIdentity = databaseGeneratedOption == DatabaseGeneratedOption.Identity;
67-
IsNullable = Nullable.GetUnderlyingType(property.PropertyType) is not null || nullabilityContext.Create(property).WriteState != NullabilityState.NotNull;
66+
IsNullable = Nullable.GetUnderlyingType(property.PropertyType) is not null || nullabilityContext.Value!.Create(property).WriteState != NullabilityState.NotNull;
6867
Name = property.GetCustomAttribute<ColumnAttribute>()?.Name ?? property.Name;
6968
}
7069

0 commit comments

Comments
 (0)