6

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?

4

1 に答える 1

10

dapper がそれを無視する理由は、 setter がないからです。プロパティが内部でどのように実装されているかは気にしませんが、プロパティを使用するにはセッターが必要です (ただし、セッターはパブリックである必要はありません)。

余談ですが、フィールドを使用することもできます。

于 2012-09-05T20:37:14.053 に答える