save work

This commit is contained in:
StellaOps Bot
2025-12-19 07:28:23 +02:00
parent 6410a6d082
commit 2eafe98d44
97 changed files with 5040 additions and 1443 deletions

View File

@@ -1,3 +1,4 @@
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Text;
using Microsoft.Extensions.Logging;
@@ -234,7 +235,30 @@ public abstract class RepositoryBase<TDataSource> where TDataSource : DataSource
configureCommand?.Invoke(command);
var result = await command.ExecuteScalarAsync(cancellationToken).ConfigureAwait(false);
return result is DBNull or null ? default : (T)result;
if (result is DBNull or null)
{
return default;
}
if (result is T typed)
{
return typed;
}
var targetType = typeof(T);
var underlyingTargetType = Nullable.GetUnderlyingType(targetType) ?? targetType;
try
{
var converted = Convert.ChangeType(result, underlyingTargetType, CultureInfo.InvariantCulture);
return (T?)converted;
}
catch (Exception ex) when (ex is InvalidCastException or FormatException or OverflowException)
{
throw new InvalidCastException(
$"Failed to convert scalar result ({result.GetType().FullName}) to {targetType.FullName} in {callerName ?? "unknown"}.",
ex);
}
}
/// <summary>