Value cannot be null when using join in OrmLite / Servicestack / Linqpad

时间:2018-06-04 16:37:15

标签: linqpad ormlite-servicestack

When joining two tables I get ArgumentNullException: Value cannot be null. Parameter name: key.

This happens after executing the query, change any line in Linqpad and execute again.

using (var db = _factory.OpenDbConnection())
{
    var q = db.From<Customer>()
    .Join<Customer, Address>();

    var results = db.SelectMulti<Customer, Address>(q); 

    results.Dump();
}

Customer

public class Customer
{
    public int Id { get; set; }
    public string Name { get; set; }
}

Address

public class Address
{
    public int Id { get; set; }
    public int CustomerId { get; set; }
}

ServiceStack throws this error

   at System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
      at System.Collections.Generic.Dictionary`2.FindEntry(TKey key)
      at System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue& value)
      at ServiceStack.TypeExtensions.GetActivator(ConstructorInfo ctor)
      at ServiceStack.OrmLite.OrmLiteUtils.ConvertToList[T](IDataReader reader, IOrmLiteDialectProvider dialectProvider, HashSet`1 onlyFields)
      at ServiceStack.OrmLite.OrmLiteResultsFilterExtensions.ExprConvertToList[T](IDbCommand dbCmd, String sql, IEnumerable`1 sqlParams, HashSet`1 onlyFields)
      at ServiceStack.OrmLite.ReadExpressionCommandExtensions.SelectMulti[T,T2](IDbCommand dbCmd, SqlExpression`1 q)
      at ServiceStack.OrmLite.OrmLiteExecFilter.Exec[T](IDbConnection dbConn, Func`2 filter)
      at UserQuery.Main() in C:\Users\kairu\AppData\Local\Temp\LINQPad5\_uimlqbjb\plnhhb\LINQPadQuery.cs:line 54
      at LINQPad.ExecutionModel.ClrQueryRunner.Run()
      at LINQPad.ExecutionModel.Server.RunQuery(QueryRunner runner)
      at LINQPad.ExecutionModel.Server.StartQuery(QueryRunner runner)
      at LINQPad.ExecutionModel.Server.<>c__DisplayClass153_0.<ExecuteClrQuery>b__0()
      at LINQPad.ExecutionModel.Server.SingleThreadExecuter.Work()
      at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
      at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
      at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
      at System.Threading.ThreadHelper.ThreadStart()

Using ServiceStack version 5.1.0 net45

1 个答案:

答案 0 :(得分:1)

This example works as expected on Gistlyn:

public class Customer
{
    public int Id { get; set; }
    public string Name { get; set; }
}

public class Address
{
    public int Id { get; set; }
    public int CustomerId { get; set; }
}

db.CreateTable<Customer>();
db.CreateTable<Address>();
db.Insert(new Customer { Id = 1, Name = "C" });
db.Insert(new Address { Id = 1, CustomerId = 1 });


var q = db.From<Customer>()
    .Join<Customer,Address>();

var results = db.SelectMulti<Customer, Address>(q);

results.PrintDump();

It might be an issue with LINQ Pad.