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

.net dapper

Question

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?

Accepted Answer

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.




Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why