【问题标题】:Enum value in tuple using ServiceStack Ormlite throws null reference exception使用 ServiceStack Ormlite 的元组中的枚举值引发空引用异常
【发布时间】:2018-11-09 23:48:18
【问题描述】:

在返回结构中使用带有枚举的元组表示法时,我得到“对象引用未设置为对象的实例”。

如果我将元组中的类型从 Enum 类型更改为字符串,它可以正常工作,如果我将它更改为只返回一个值(字符串或枚举),它也可以正常工作。

它是 ServiceStack 中的错误吗? 我在 LinqPad v5.31.0 中运行 ServiceStack.OrmLite.SqlServer v5.4.0

void Main()
{
    var uniqueId = "a635266024448923446";
    var result = new Dictionary<Language, string>();

    using (var db = _connectionFactory.OpenDbConnection())
    {
        // This works fine    
        var rows1 = db.Select<A>("select LanguageId, Name from tblTable");
        foreach (var row in rows1)
        {
            result.Add(row.LanguageId, row.Name);
        }
    }

    using (var db = _connectionFactory.OpenDbConnection())
    {

        // This throws "Object reference not set to an instance of an object."
        var rows2 = db.Select<(Language Language, string Name)>("select LanguageId, Name from tblTable");
        foreach (var row in rows2)
        {           
            result.Add(row.Language, row.Name);
        }
    }
}

public class A
{
    public Language LanguageId { get; set; }
    public string Name { get; set; }
}

public enum Language
{
    NO,
    EN,
    SV,
    DK
}

【问题讨论】:

    标签: servicestack ormlite-servicestack


    【解决方案1】:

    此更改应从this commit 解决。

    此更改从 v5.4.1 开始可用,现在为 available on MyGet

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-19
      • 1970-01-01
      • 1970-01-01
      • 2016-02-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多