【问题标题】:ServiceStack LoadSelect throws ArgumentNull when child reference is null当子引用为空时,ServiceStack LoadSelect 抛出 ArgumentNull
【发布时间】:2014-09-18 02:20:55
【问题描述】:

我有一个数据模型,其中对象的子引用可能为空(即,可能未在帐户上设置辅助地址)。当我尝试在父实体上 LoadSelect 时,我收到 ArgumentNullException: Value cannot be null. 错误,表面上是在加载子引用时。

考虑到这种数据场景的普遍性,我是不是做错了什么?否则,这是LoadListWithReferences 的缺陷吗?

我创建了一个小示例程序来说明这种行为:

using ServiceStack.DataAnnotations;
using ServiceStack.OrmLite;
using System.Collections.Generic;
using System.Data;


namespace SSLoadSelectTest
{
    public class Parent
    {
        [PrimaryKey]
        public int Id { get; set; }

        [References(typeof(Child))]
        public int? ChildId { get; set; }

        [Reference]
        public Child Child { get; set; }
    }

    public class Child
    {
        [PrimaryKey]
        public int Id { get; set; }
        public string Value { get; set; }
    }

    class Program
    {
        static void Main(string[] args)
        {
            OrmLiteConfig.DialectProvider = SqliteDialect.Provider;

            IDbConnection Db = SqliteDialect.Provider.CreateConnection(":memory:", new Dictionary<string, string>());
            Db.Open();

            Db.CreateTables(true, typeof(Parent), typeof(Child));

            Db.Insert<Child>(new Child() { Id = 1, Value = "Hello" });
            Db.Insert<Parent>(new Parent() { Id = 1, ChildId = (int)Db.LastInsertId() });
            Db.Insert<Parent>(new Parent() { Id = 2, ChildId = null });

            var results1 = Db.LoadSelect<Parent>(p => p.Id == 1);
            var results2 = Db.LoadSelect<Parent>(p => p.Id == 2);
        }
    }
}

【问题讨论】:

    标签: servicestack ormlite-servicestack


    【解决方案1】:

    这个问题现在有been fixed with this commit

    此修复可从 v4.0.32+(现在为 available on MyGet)获得。

    【讨论】:

      猜你喜欢
      • 2011-04-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-26
      • 1970-01-01
      • 2016-03-26
      • 1970-01-01
      • 2015-03-10
      • 2020-08-20
      相关资源
      最近更新 更多