user1820686
user1820686

Reputation: 2117

Dapper FluentMap: property with name 'Date' can't be mapped

I've faced the problem with Dapper FluentMap (version 1.60) which I don't know how to fix. It looks like Dapper can't map a column from a table if the corresponding property in .NET class has "Date" name.

I have the table in DB (I'm using MS SQL if that's matter) with column Dt of Date type.

There is an entity with DateTime property:

public class MyEntity {
    public DateTime Date { get; set; }
}

and the corresponding mapping:

public class MyEntityMapper : EntityMap<MyEntity> {
    public MyEntityMapper() {
        Map(p => p.Date).ToColumn("Dt");
    }
}

When I try to get data from the DB and map to MyEntity, I get the following error:

ArgumentNullException: Value cannot be null. Parameter name: meth

If I rename Date property in MyEntity to something else like Dt or JustDate - everything works fine. Is there such restriction in Dapper Fluent Map (not allowed to give a name to property equal to data type name in DB)? If so, is it possible to overcome it somehow? Because in my case it's a bit problematic to rename property in MyEntity

Upvotes: 0

Views: 771

Answers (1)

McNiel Viray
McNiel Viray

Reputation: 101

Yes you are right, the only solution you can do was to change your entity property Date into other name.

Upvotes: 1

Related Questions