renathy
renathy

Reputation: 5355

Not able to make Dapper query mapping case insensitive

string query = $@"SELECT m.* FROM Table1";   
return await dbConnection.QueryAsync<Job>();

In Oracle database table Table1 contains many columns and I do not want to specify all of them. Columns are returned in UPPERCASE, but in .NET we use CamelCase (IsActive etc.). In a result uppercase columns are never mapped to CamelCase in code. (In reality query is more complex and there is also some custom maps and splitOn option).

Is it possible to solve with Dapper?

Upvotes: 3

Views: 9261

Answers (2)

Void Ray
Void Ray

Reputation: 10209

Dapper's SqlMapper should be case-insensitive

You can test it with:

public class Result
{
    public int Id { get; set; }
    public string Value { get; set; }
}

[TestFixture]
public class Tests
{
    [Test]
    public async Task TestCaseSensitivity()
    {
        using (var conn = new SqlConnection(@"Data Source=.\sqlexpress; Integrated Security=true; Initial Catalog=test"))
        {
            var result = await conn.QueryFirstAsync<Result>("select ID = 1, VALUE = 'hello world'");
            Assert.That(result.Id, Is.EqualTo(1));
            Assert.That(result.Value, Is.EqualTo("hello world"));
        }
    }
}

Upvotes: 8

mauridb
mauridb

Reputation: 1569

AFAIK Dapper is case sensitive (as C# is). You should use FluentMap that gives all the flexibility you need to map database columns to class attributes:

https://www.nuget.org/packages/Dapper.FluentMap

Upvotes: 0

Related Questions