Skip to content

Commit c868c60

Browse files
authored
V11: Fix decimal variants (#13741)
* fix sqlite with variants * Create and register SqlSpecificMapper * Delete obsolete file * Add back inheritance Co-authored-by: Zeegaan <[email protected]>
1 parent be0138e commit c868c60

File tree

4 files changed

+62
-0
lines changed

4 files changed

+62
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using Umbraco.Cms.Core.Mapping;
2+
using Umbraco.Cms.Infrastructure.Persistence;
3+
4+
namespace Umbraco.Cms.Persistence.SqlServer.Services;
5+
6+
public class SqlServerSpecificMapperFactory : IProviderSpecificMapperFactory
7+
{
8+
public string ProviderName => Constants.ProviderName;
9+
10+
public NPocoMapperCollection Mappers => new(() => new[] { new UmbracoDefaultMapper() });
11+
}

src/Umbraco.Cms.Persistence.SqlServer/UmbracoBuilderExtensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public static class UmbracoBuilderExtensions
2222
/// </summary>
2323
public static IUmbracoBuilder AddUmbracoSqlServerSupport(this IUmbracoBuilder builder)
2424
{
25+
builder.Services.TryAddEnumerable(ServiceDescriptor
26+
.Singleton<IProviderSpecificMapperFactory, SqlServerSpecificMapperFactory>());
2527
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<ISqlSyntaxProvider, SqlServerSyntaxProvider>());
2628
builder.Services.TryAddEnumerable(ServiceDescriptor
2729
.Singleton<IBulkSqlInsertProvider, SqlServerBulkSqlInsertProvider>());

src/Umbraco.Cms.Persistence.Sqlite/Mappers/SqlitePocoGuidMapper.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Globalization;
12
using NPoco;
23

34
namespace Umbraco.Cms.Persistence.Sqlite.Mappers;
@@ -28,6 +29,24 @@ public class SqlitePocoGuidMapper : DefaultMapper
2829
};
2930
}
3031

32+
if (destType == typeof(decimal))
33+
{
34+
return value =>
35+
{
36+
var result = Convert.ToDecimal(value, CultureInfo.InvariantCulture);
37+
return result;
38+
};
39+
}
40+
41+
if (destType == typeof(decimal?))
42+
{
43+
return value =>
44+
{
45+
var result = Convert.ToDecimal(value, CultureInfo.InvariantCulture);
46+
return result;
47+
};
48+
}
49+
3150
return base.GetFromDbConverter(destType, sourceType);
3251
}
3352
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System.Globalization;
2+
using NPoco;
3+
4+
namespace Umbraco.Cms.Core.Mapping;
5+
6+
public class UmbracoDefaultMapper : DefaultMapper
7+
{
8+
public override Func<object, object?> GetFromDbConverter(Type destType, Type sourceType)
9+
{
10+
if (destType == typeof(decimal))
11+
{
12+
return value =>
13+
{
14+
var result = Convert.ToDecimal(value, CultureInfo.InvariantCulture);
15+
return result;
16+
};
17+
}
18+
19+
if (destType == typeof(decimal?))
20+
{
21+
return value =>
22+
{
23+
var result = Convert.ToDecimal(value, CultureInfo.InvariantCulture);
24+
return result;
25+
};
26+
}
27+
28+
return base.GetFromDbConverter(destType, sourceType);
29+
}
30+
}

0 commit comments

Comments
 (0)