本文介绍了枚举存储在数据库中的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我与短小精悍的实验。我有一个枚举和值存储在数据库中的字符串一类。
I am experimenting with dapper. I have a class which has an enum and the values are stored as strings in the database.
这适用于使用GenericEnumMapper FluentNHibernate
This works with FluentNHibernate using GenericEnumMapper
是否有可能做同样的小巧玲珑的?
Is it possible to do the same with Dapper?
推荐答案
这是不是建立在目前,有就是这个在这里提议的解决方案:我们还没有决定。我喜欢扩展型转换器的想法
This is not built in at the moment, there is a proposed solution for this here: http://code.google.com/p/dapper-dot-net/issues/detail?id=24 which we are yet to decide on. I like the idea of extensible type converters
因为它的立场这样做是定义shadow属性如干净的方式:
As it stands the cleanest way to do this would be to define shadow property eg:
class MyType
{
public MyEnum MyEnum {get; private set;}
private string DBEnum { set { MyEnum = Convert(value);} }
private MyEnum Convert(string val)
{
// TODO: Write me
}
}
// cnn.Query<MyType>("select 'hello' as DBEnum") <-- will set MyEnum
这篇关于枚举存储在数据库中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!