Map string to guid with Dapper

前端 未结 6 507
广开言路
广开言路 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:26

    Perhaps the simplest way to do this (without waiting on dapper) is to have a second property:

    public Guid Foo {get;set;}
    
    public string FooString {
        get { return Foo.ToString("N"); }
        set { Foo = new Guid(value); }
    }
    

    And in your query, alias the column as FooString.

    Of course, then this prompts the question: should dapper support private properties for this type of thing? To which I say: probably.

提交回复
热议问题