Skip to content

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

Open
@Freysev

Description

@Freysev

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingwontfixThis will not be worked onworking-as-expectedThe reported issue is working as expected.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions