V11: Fix decimal variants (#13741)
* fix sqlite with variants * Create and register SqlSpecificMapper * Delete obsolete file * Add back inheritance Co-authored-by: Zeegaan <nge@umbraco.dk>
This commit is contained in:
@@ -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() });
|
||||
}
|
||||
@@ -22,6 +22,8 @@ public static class UmbracoBuilderExtensions
|
||||
/// </summary>
|
||||
public static IUmbracoBuilder AddUmbracoSqlServerSupport(this IUmbracoBuilder builder)
|
||||
{
|
||||
builder.Services.TryAddEnumerable(ServiceDescriptor
|
||||
.Singleton<IProviderSpecificMapperFactory, SqlServerSpecificMapperFactory>());
|
||||
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<ISqlSyntaxProvider, SqlServerSyntaxProvider>());
|
||||
builder.Services.TryAddEnumerable(ServiceDescriptor
|
||||
.Singleton<IBulkSqlInsertProvider, SqlServerBulkSqlInsertProvider>());
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
30
src/Umbraco.Infrastructure/Mapping/UmbracoDefaultMapper.cs
Normal file
30
src/Umbraco.Infrastructure/Mapping/UmbracoDefaultMapper.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System.Globalization;
|
||||
using NPoco;
|
||||
|
||||
namespace Umbraco.Cms.Core.Mapping;
|
||||
|
||||
public class UmbracoDefaultMapper : DefaultMapper
|
||||
{
|
||||
public override Func<object, object?> 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user