diff --git a/src/Marten/Schema/Identity/ValueTypeIdGeneration.cs b/src/Marten/Schema/Identity/ValueTypeIdGeneration.cs index 0a58c1dfdd..3d837b506c 100644 --- a/src/Marten/Schema/Identity/ValueTypeIdGeneration.cs +++ b/src/Marten/Schema/Identity/ValueTypeIdGeneration.cs @@ -2,6 +2,7 @@ using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Linq.Expressions; +using System.Numerics; using System.Reflection; using System.Threading; using JasperFx.CodeGeneration; @@ -133,6 +134,10 @@ public ISelectClause BuildSelectClause(string tableName) public static bool IsCandidate(Type idType, [NotNullWhen(true)]out ValueTypeIdGeneration? idGeneration) { + idGeneration = default; + if (idType == typeof(Type)) return false; + if (idType == typeof(BigInteger)) return false; + if (idType.IsGenericType && idType.IsNullable()) { idType = idType.GetGenericArguments().Single(); @@ -144,11 +149,6 @@ public static bool IsCandidate(Type idType, [NotNullWhen(true)]out ValueTypeIdGe return false; } - if (!idType.Name.EndsWith("Id")) - { - return false; - } - if (!idType.IsPublic && !idType.IsNestedPublic) { return false; diff --git a/src/ValueTypeTests/TestingTypes.cs b/src/ValueTypeTests/TestingTypes.cs index e45c558251..72a484cdf4 100644 --- a/src/ValueTypeTests/TestingTypes.cs +++ b/src/ValueTypeTests/TestingTypes.cs @@ -11,6 +11,9 @@ namespace ValueTypeTests; [ValueObject] public readonly partial struct IntId; +[ValueObject] +public readonly partial struct WeirdNamed; + [ValueObject] public readonly partial struct LongId; diff --git a/src/ValueTypeTests/applicability_of_identity_types.cs b/src/ValueTypeTests/applicability_of_identity_types.cs index 15e32364bc..357aca541f 100644 --- a/src/ValueTypeTests/applicability_of_identity_types.cs +++ b/src/ValueTypeTests/applicability_of_identity_types.cs @@ -13,6 +13,7 @@ public class applicability_of_identity_types [InlineData(typeof(string), false)] [InlineData(typeof(GuidId), true)] [InlineData(typeof(IntId), true)] + [InlineData(typeof(WeirdNamed), true)] [InlineData(typeof(LongId), true)] [InlineData(typeof(StringId), true)] [InlineData(typeof(GuidId?), true)] @@ -47,6 +48,7 @@ public void FSharpIdGeneration_IsCandidate(Type candidate, bool isCandidate) [Theory] [InlineData(typeof(GuidId), typeof(GuidId), typeof(ValueTypeIdGeneration))] [InlineData(typeof(IntId), typeof(IntId), typeof(ValueTypeIdGeneration))] + [InlineData(typeof(WeirdNamed), typeof(WeirdNamed), typeof(ValueTypeIdGeneration))] [InlineData(typeof(LongId), typeof(LongId), typeof(ValueTypeIdGeneration))] [InlineData(typeof(StringId), typeof(StringId), typeof(ValueTypeIdGeneration))] [InlineData(typeof(GuidId?), typeof(GuidId), typeof(ValueTypeIdGeneration))]