diff --git a/src/Umbraco.Cms.Persistence.SqlServer/Services/SqlServerSpecificMapperFactory.cs b/src/Umbraco.Cms.Persistence.SqlServer/Services/SqlServerSpecificMapperFactory.cs new file mode 100644 index 0000000000..1943aa251a --- /dev/null +++ b/src/Umbraco.Cms.Persistence.SqlServer/Services/SqlServerSpecificMapperFactory.cs @@ -0,0 +1,11 @@ +using Umbraco.Cms.Core.Mapping; +using Umbraco.Cms.Infrastructure.Persistence; + +namespace Umbraco.Cms.Persistence.SqlServer.Services; + +public class SqlServerSpecificMapperFactory : IProviderSpecificMapperFactory +{ + public string ProviderName => Constants.ProviderName; + + public NPocoMapperCollection Mappers => new(() => new[] { new UmbracoDefaultMapper() }); +} diff --git a/src/Umbraco.Cms.Persistence.SqlServer/UmbracoBuilderExtensions.cs b/src/Umbraco.Cms.Persistence.SqlServer/UmbracoBuilderExtensions.cs index a47e92bf2e..cbded6a623 100644 --- a/src/Umbraco.Cms.Persistence.SqlServer/UmbracoBuilderExtensions.cs +++ b/src/Umbraco.Cms.Persistence.SqlServer/UmbracoBuilderExtensions.cs @@ -22,6 +22,8 @@ public static class UmbracoBuilderExtensions /// public static IUmbracoBuilder AddUmbracoSqlServerSupport(this IUmbracoBuilder builder) { + builder.Services.TryAddEnumerable(ServiceDescriptor + .Singleton()); builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton()); builder.Services.TryAddEnumerable(ServiceDescriptor .Singleton()); diff --git a/src/Umbraco.Cms.Persistence.Sqlite/Mappers/SqlitePocoGuidMapper.cs b/src/Umbraco.Cms.Persistence.Sqlite/Mappers/SqlitePocoGuidMapper.cs index 930478e453..ab62b4b1d1 100644 --- a/src/Umbraco.Cms.Persistence.Sqlite/Mappers/SqlitePocoGuidMapper.cs +++ b/src/Umbraco.Cms.Persistence.Sqlite/Mappers/SqlitePocoGuidMapper.cs @@ -1,3 +1,4 @@ +using System.Globalization; using NPoco; namespace Umbraco.Cms.Persistence.Sqlite.Mappers; @@ -28,6 +29,24 @@ public class SqlitePocoGuidMapper : DefaultMapper }; } + if (destType == typeof(decimal)) + { + return value => + { + var result = Convert.ToDecimal(value, CultureInfo.InvariantCulture); + return result; + }; + } + + if (destType == typeof(decimal?)) + { + return value => + { + var result = Convert.ToDecimal(value, CultureInfo.InvariantCulture); + return result; + }; + } + return base.GetFromDbConverter(destType, sourceType); } } diff --git a/src/Umbraco.Infrastructure/Mapping/UmbracoDefaultMapper.cs b/src/Umbraco.Infrastructure/Mapping/UmbracoDefaultMapper.cs new file mode 100644 index 0000000000..986bb19d39 --- /dev/null +++ b/src/Umbraco.Infrastructure/Mapping/UmbracoDefaultMapper.cs @@ -0,0 +1,30 @@ +using System.Globalization; +using NPoco; + +namespace Umbraco.Cms.Core.Mapping; + +public class UmbracoDefaultMapper : DefaultMapper +{ + public override Func GetFromDbConverter(Type destType, Type sourceType) + { + if (destType == typeof(decimal)) + { + return value => + { + var result = Convert.ToDecimal(value, CultureInfo.InvariantCulture); + return result; + }; + } + + if (destType == typeof(decimal?)) + { + return value => + { + var result = Convert.ToDecimal(value, CultureInfo.InvariantCulture); + return result; + }; + } + + return base.GetFromDbConverter(destType, sourceType); + } +}