【发布时间】:2015-07-23 04:01:30
【问题描述】:
OrmLite SqlList 不适用于 可为空的枚举 属性?
public static List<T> SqlList<T> (this IDbConnection dbConn, string sql, object anonType = null);
如果我有这样的枚举
public enum WorkStatus
{
Started = 0,
Ended = 1
}
我有一个像这样的对象
public class Query
{
//nullable enum won't work
public WorkStatus? NotWork { get; set; }
//but non nullable enum will work
public WorkStatus Work { get; set; }
}
当我这样做时
//conn is of type IDbConnection
//ignored where clause in raw sql just for the simplicity
conn.SqlList<T>(@"select * from works", new Query());
如果我只有不可为空的枚举,查询工作正常,如果我只有可空的枚举,查询将抛出异常
LEVEL:ERROR CLASS:ServiceStack.DtoUtils ServiceBase::Service 异常 System.Collections.Generic.KeyNotFoundException:给定的键不在字典中。 在 System.ThrowHelper.ThrowKeyNotFoundException () [0x00000] 在 /private/tmp/source-mono-mac-4.0.0-branch-c5sr2/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build -root/mono-4.0.2/external/referencesource/mscorlib/system/throwhelper.cs:70 在 System.Collections.Generic.Dictionary
2<System.Type, System.Data.DbType>.get_Item (System.Type) [0x00021] in /private/tmp/source-mono-mac-4.0.0-branch-c5sr2/bockbuild-mono-4.0.0-branch/profiles/mono-mac-xamarin/build-root/mono-4.0.2/external/referencesource/mscorlib/system/collections/generic/dictionary.cs:176 at ServiceStack.OrmLite.OrmLiteDialectProviderBase1.GetColumnDbType (System.Type)
我正在使用单声道,但我怀疑这会是原因。数据库是mysql。听起来“GetColumnDbType”不支持可为空的枚举。
任何建议将不胜感激。
【问题讨论】:
标签: c# mysql enums servicestack ormlite-servicestack