Closed GoogleCodeExporter closed 9 years ago
Oh, I forgot: I'm using latest available NuGet package (Dapper 1.4).
Original comment by marcin.s...@expertsender.com
on 4 Jul 2011 at 3:01
Sounds like something that should work; I'm happy to take a look later
Original comment by marc.gravell
on 4 Jul 2011 at 3:04
Let me post a temporary workaround I did:
I have devised a solution for "custom" mapping of selected columns. It could
come in handy if you encounter problem such as mine or if you want to map some
columns in different way than default.
The trick is to use Dapper's multimapping.
When there is only one column you want to map differently, you may map it to
simple type, e.g:
var sql = "SELECT Id, Foo, Bar AS Id FROM Test";
Connection.Query<Test, string, Test>(sql, (test, bar) =>
{
test.Bar = bar.ToLower();
return test;
});
As you can see, "Bar" column is mapped to separate string and ToLowered before
injecting into Test object.
Note that "Bar" column is named as "Id", so Dapper can differentiate it as new
entity.
If you have multiple columns you want to exclude from "normal" mapping, you can
map them to dynamic object:
var sql = "SELECT Id, 1 AS Id, Foo, Bar FROM Test";
Connection.Query<Test, dynamic, Test>(sql, (test, fooBars) =>
{
test.Foo = fooBars.Foo.ToLower();
test.Bar = fooBars.Bar.ToLower();
return test;
});
Note that fake Id column is added to select, so Dapper can split the record
into two entities.
Of course, this method is cumbersome, because you always have to list all
columns you want to select, instead of using "*", but it works.
Still, I'd rather use my generic DAOs for these char fields, so looking forward
for new version. ;)
Original comment by marcin.s...@expertsender.com
on 4 Jul 2011 at 5:58
Fixed in code; not yet deployed
Original comment by marc.gravell
on 4 Jul 2011 at 9:48
fixed in code, to be pushed to nuget later today
Original comment by sam.saff...@gmail.com
on 11 Jul 2011 at 11:30
Original issue reported on code.google.com by
marcin.s...@expertsender.com
on 4 Jul 2011 at 2:59