Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will Dapper not work with members that have custom getters/setters?

Tags:

.net

dapper

Based on some code I am working with this appears to be the case. I couldn't find anything in the dapper documentation that explicitly said that it won't work with members that have custom get/set logic, but I did see this example:

public class Dog
{
    public int? Age { get; set; }
    public Guid Id { get; set; }
    public string Name { get; set; }
    public float? Weight { get; set; }

    public int IgnoredProperty { get { return 1; } }  //red flag?
}           

It seems like the fact that the one member that has custom get behavior is prefixed with Ignored might suggest that Dapper will not try to populate these values. Is this true? Is this in the documentation and I just overlooked it?

like image 630
Abe Miessler Avatar asked Sep 05 '12 20:09

Abe Miessler


1 Answers

The reason dapper will ignore that one is that it doesn't have a setter. It doesn't care how your properties are implemented internally, but it needs a setter to use a property (although the setter doesn't have to be public).

It can also use fields, as an aside.

like image 120
Marc Gravell Avatar answered Nov 15 '22 08:11

Marc Gravell