Skip to content

Commit 7232670

Browse files
quick update
1 parent 1f2397f commit 7232670

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

Magic.IndexedDb/Helpers/PropertyMappingCache.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@ public SearchPropEntry(Type type, Dictionary<string, MagicPropertyEntry> _proper
2727
jsNameToCsName[entry.Value.JsPropertyName] = entry.Value.CsharpPropertyName;
2828
}
2929

30+
// Extract MagicTableAttribute info
31+
var magicTableAttr = type.GetCustomAttribute<MagicTableAttribute>();
32+
if (magicTableAttr != null && !string.IsNullOrWhiteSpace(magicTableAttr.SchemaName))
33+
{
34+
EffectiveTableName = magicTableAttr.SchemaName; // Use the schema name
35+
EnforcePascalCase = true; // Prevent camel casing
36+
}
37+
else
38+
{
39+
EffectiveTableName = type.Name; // Default to class name
40+
EnforcePascalCase = false;
41+
}
42+
3043
// 🔥 Pick the best constructor: Prefer a parameterized one, else fallback to parameterless
3144
var constructor = constructors.OrderByDescending(c => c.GetParameters().Length).FirstOrDefault();
3245
Constructor = constructor; // ✅ Assign to instance variable
@@ -57,6 +70,9 @@ public SearchPropEntry(Type type, Dictionary<string, MagicPropertyEntry> _proper
5770
}
5871
}
5972

73+
public string EffectiveTableName { get; } // ✅ Stores the final name (SchemaName or C# class name)
74+
public bool EnforcePascalCase { get; } // ✅ If true, prevents camel casing
75+
6076
public ConstructorInfo? Constructor { get; } // ✅ Stores the most relevant constructor
6177
public bool HasConstructorParameters { get; } // ✅ Cached flag to avoid checking length
6278
public Func<object?[], object?> InstanceCreator { get; } // ✅ Cached instance creator
@@ -422,8 +438,11 @@ internal static void EnsureTypeIsCached(Type type)
422438
property.IsDefined(typeof(MagicUniqueIndexAttribute), inherit: true),
423439
property.IsDefined(typeof(MagicPrimaryKeyAttribute), inherit: true),
424440
property.IsDefined(typeof(MagicNotMappedAttribute), inherit: true),
425-
hasMagicTableAttribute || property.IsDefined(typeof(MagicNameAttribute), inherit: true)
441+
hasMagicTableAttribute
442+
|| property.IsDefined(typeof(MagicNameAttribute), inherit: true)
443+
|| property.IsDefined(typeof(MagicTableAttribute), inherit: true)
426444
);
445+
427446
newMagicPropertyEntry.Add(magicEntry);
428447
propertyEntries[propertyKey] = magicEntry; // Store property entry with string key
429448
}

0 commit comments

Comments
 (0)