Map string to guid with Dapper

前端 未结 6 541
广开言路
广开言路 2020-12-30 03:48

I\'m using Dapper to hammer out some load testing tools that need to access a PostgreSQL database. This particular version of PostgreSQL does not support GUIDs natively, so

6条回答
  •  醉酒成梦
    2020-12-30 04:24

    This is an old question but I feel it needs updating as Dapper now supports private properties, which Marc referenced to in his answer.

    private String UserIDString { get; set; }
    public Guid UserID
    {
        get
        {
            return new Guid(UserIDString);
        }
        private set
        {
            UserID = value;
        }
    }
    

    Then in SQL give your ID column an alias to map it to the private property and not the actual property:

    SELECT UserID AS UserIDString FROM....
    

提交回复
热议问题