RepoDB: Bug: RepoDb.SqlServer v1.1.3: Failing to map ENUM to INT

Bug Description

Hello. I’m encountering an issue when im trying to insert or merge a class with an enum in it. I’ve tried adding a [TypeMap(DbType.Int32)] attribute, but it doesnt change anything.

Exception Message:

Compiler.Entity/Object.Property: Failed to automatically convert the value expression 
for property 'Resolution (XXX.YYY.PeriodResolution)'. 
ClassProperty :: Name = Resolution (XXX.YYY.PeriodResolution), DeclaringType = 
XXX.YYY.Models.Entities.MarketPrice

InnerException: Expression of type 'XXX.YYY.PeriodResolution' 
cannot be used for parameter of type 'System.Int32' of method 'Int32 ToInt32(Int32)' (Parameter 'arg0')

InnerException.StackTrace: 
   at System.Dynamic.Utils.ExpressionUtils.ValidateOneArgument(MethodBase method, ExpressionType nodeKind, Expression arguments, ParameterInfo pi, String methodParamName, String argumentParamName, Int32 index)
   at System.Linq.Expressions.Expression.Call(MethodInfo method, Expression arg0)
   at RepoDb.Reflection.Compiler.ConvertExpressionToSystemConvertExpression(Expression expression, Type toType)
   at RepoDb.Reflection.Compiler.ConvertExpressionWithAutomaticConversion(Expression expression, Type toType)
   at RepoDb.Reflection.Compiler.GetEntityInstancePropertyValueExpression(Expression entityInstanceExpression, ClassProperty classProperty, DbField dbField)

Schema and Model:

CREATE TABLE [dbo].[MarketPrices]
(
    [Product] VARCHAR(50) NOT NULL, 
    [Resolution] INT NOT NULL, 
    [Period] INT NOT NULL, 
    [Value ] DECIMAL(18, 3) NOT NULL, 
    Primary key ([Product], [Resolution], [Period])
)
    [Map("[dbo].[MarketPrices]")]
    public class MarketPrice
    {
        public string Product { get; set; }
        [TypeMap(DbType.Int32)]
        public PeriodResolution Resolution { get; set; }
        public int Period{ get; set; }
        public decimal Value { get; set; }
    }

    public enum PeriodResolution
    {
        [Description("Uke")]
        Week,
        [Description("Måned")]
        Month,
        [Description("Kvartal")]
        Quarter,
        [Description("År")]
        Year,
        [Description("Egendefinert")]
        Custom
    }

Library Version:

RepoDb.SqlServer v1.1.3 .NET Core 3.1

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 18 (13 by maintainers)

Most upvoted comments

Hey, i’m quite busy with other stuff atm, but hopefully i’ll get around to replicating with your project later this week or next weekend