本文介绍了地图字符串与精致小巧的GUID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用小巧精致的推敲出一些需要访问PostgreSQL数据库的负载测试工具。 PostgreSQL的这个特殊版本不支持原生的GUID,所以GUID值存储为32字符串。这些值转换为使用 someGuid.ToString(N),转换回的Guid可以使用字符串做新的GUID(stringValueFromColumn)

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 GUID values are stored as 32 character strings. The values are converted to strings using someGuid.ToString("N"), conversion back to Guid can be done using new Guid(stringValueFromColumn).

我的问题是我怎么小巧玲珑的读取字符串,并将其转换回的GUID?

My question is how do I get Dapper to read the strings and convert them back to Guids?

我试图修改的DbType映射,但不起作用。

I tried modifying the DbType mapping but that doesn't work.

推荐答案

也许最简单的方式做到这一点(无需等待上短小精悍)是有第二个属性:

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); }
}

和您的查询,别名列 。FooString

当然,那么这个提示问题:应该短小精悍支持专用属性这种类型的事情?要我说:可能

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

这篇关于地图字符串与精致小巧的GUID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 08:40