Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions RepoDb.Core/RepoDb/Cachers/Types/DbFieldCollection.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Linq;
using RepoDb.Extensions;
Expand All @@ -15,8 +16,8 @@ public class DbFieldCollection
private readonly IReadOnlyList<DbField> dbFields;
private readonly Lazy<IEnumerable<Field>> lazyFields;
private readonly Lazy<DbField> lazyIdentity;
private readonly Lazy<Dictionary<string, DbField>> lazyMapByName;
private readonly Lazy<Dictionary<string, DbField>> lazyMapByUnquotedName;
private readonly Lazy<FrozenDictionary<string, DbField>> lazyMapByName;
private readonly Lazy<FrozenDictionary<string, DbField>> lazyMapByUnquotedName;
private readonly Lazy<DbField> lazyPrimary;

/// <summary>
Expand All @@ -31,8 +32,8 @@ public DbFieldCollection(IEnumerable<DbField> dbFields, IDbSetting dbSetting)

lazyPrimary = new Lazy<DbField>(GetPrimaryDbField);
lazyIdentity = new Lazy<DbField>(GetIdentityDbField);
lazyMapByName = new Lazy<Dictionary<string, DbField>>(GetDbFieldsMappedByName);
lazyMapByUnquotedName = new Lazy<Dictionary<string, DbField>>(GetDbFieldsMappedByUnquotedName);
lazyMapByName = new Lazy<FrozenDictionary<string, DbField>>(GetDbFieldsMappedByName);
lazyMapByUnquotedName = new Lazy<FrozenDictionary<string, DbField>>(GetDbFieldsMappedByUnquotedName);
lazyFields = new Lazy<IEnumerable<Field>>(GetDbFieldsAsFields);
}

Expand Down Expand Up @@ -90,11 +91,11 @@ public DbField GetByUnquotedName(string name)
return dbField;
}

private Dictionary<string, DbField> GetDbFieldsMappedByName() =>
dbFields.ToDictionary(df => df.Name, df => df, StringComparer.OrdinalIgnoreCase);
private FrozenDictionary<string, DbField> GetDbFieldsMappedByName() =>
dbFields.ToFrozenDictionary(df => df.Name, df => df, StringComparer.OrdinalIgnoreCase);

private Dictionary<string, DbField> GetDbFieldsMappedByUnquotedName() =>
dbFields.ToDictionary(df => df.Name.AsUnquoted(true, dbSetting), df => df, StringComparer.OrdinalIgnoreCase);
private FrozenDictionary<string, DbField> GetDbFieldsMappedByUnquotedName() =>
dbFields.ToFrozenDictionary(df => df.Name.AsUnquoted(true, dbSetting), df => df, StringComparer.OrdinalIgnoreCase);

private DbField GetPrimaryDbField() => dbFields.FirstOrDefault(df => df.IsPrimary);

Expand Down
4 changes: 4 additions & 0 deletions RepoDb.Core/RepoDb/RepoDb.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
<PackageReference Include="System.Memory" Version="4.5.5" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' != 'net8.0'">
<PackageReference Include="System.Collections.Immutable" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
<None Include="..\..\LICENSE.txt">
<Pack>True</Pack>
Expand Down