Skip to content

Bug: Type with custom mapping used in an array is not mapped to specific DBType #1053

@rafek1241

Description

@rafek1241

Bug Description

Type with custom mapping used in an array is not mapped to specific DBType.
After reverse engineering and investigation I found that the issue is related to: https://github.com/mikependon/RepoDB/blob/master/RepoDb.Core/RepoDb/Extensions/DbCommandExtension.cs#L143 where there is no mapping of array parameter to specific type and instead null was used.

Exception Message:

No mapping exists from object type <type> to a known managed provider native type.

Schema and Model:

var c = new SqlConnection();
TypeMapper.Add<VarcharKey>(DbType.AnsiString, true);

//Working and maps correctly to the `varchar` string 👌
var query = "SELECT * FROM A WHERE A.KEY = @KEY";
await c.ExecuteQueryAsync(query, new { Key = new VarcharKey("key")});


//Not working entirely ❌
var query = "SELECT * FROM A WHERE A.KEY IN (@KEYS)";
await c.ExecuteQueryAsync(query, new { Keys = new VarcharKey[]{ "key" }});

And also the model that corresponds the schema.

public class A {
public string Key {get;set;} //it's a varchar in the database
}

Varchar key type:

 internal sealed record VarcharKey(string Value) : IConvertible
    {
        public static implicit operator string(VarcharKey source) => source.Value;
        public static implicit operator VarcharKey(string source) => new VarcharKey(source);
        
        public TypeCode GetTypeCode() => throw new NotImplementedException();

        public bool ToBoolean(IFormatProvider? provider) => throw new NotImplementedException();

        public byte ToByte(IFormatProvider? provider) => throw new NotImplementedException();

        public char ToChar(IFormatProvider? provider) => throw new NotImplementedException();

        public DateTime ToDateTime(IFormatProvider? provider) => throw new NotImplementedException();

        public decimal ToDecimal(IFormatProvider? provider) => throw new NotImplementedException();

        public double ToDouble(IFormatProvider? provider) => throw new NotImplementedException();

        public short ToInt16(IFormatProvider? provider) => throw new NotImplementedException();

        public int ToInt32(IFormatProvider? provider) => throw new NotImplementedException();

        public long ToInt64(IFormatProvider? provider) => throw new NotImplementedException();

        public sbyte ToSByte(IFormatProvider? provider) => throw new NotImplementedException();

        public float ToSingle(IFormatProvider? provider) => throw new NotImplementedException();

        public string ToString(IFormatProvider? provider) => Value;

        public object ToType(Type conversionType, IFormatProvider? provider) => throw new NotImplementedException();

        public ushort ToUInt16(IFormatProvider? provider) => throw new NotImplementedException();

        public uint ToUInt32(IFormatProvider? provider) => throw new NotImplementedException();

        public ulong ToUInt64(IFormatProvider? provider) => throw new NotImplementedException();
    }

Library Version:

RepoDb v1.12.10 and RepoDb.SqlServer v1.1.5

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingfixedThe bug, issue, incident has been fixed.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions