Skip to content
This repository has been archived by the owner on Dec 24, 2022. It is now read-only.

Commit

Permalink
Clear OrderBy in LoadList subselect
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Oct 30, 2014
1 parent e33aad4 commit 8d328f4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/ServiceStack.OrmLite/Support/LoadList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ protected LoadList(IDbCommand dbCmd, SqlExpression<From> expr)
modelDef = ModelDefinition<Into>.Definition;
fieldDefs = modelDef.AllFieldDefinitionsArray.Where(x => x.IsReference).ToList();

expr.Select(dialectProvider.GetQuotedColumnName(modelDef, modelDef.PrimaryKey));
expr.Select(dialectProvider.GetQuotedColumnName(modelDef, modelDef.PrimaryKey))
.OrderBy(""); //Invalid in Sub Selects
subSql = expr.ToSelectStatement();
}

Expand Down
14 changes: 14 additions & 0 deletions tests/ServiceStack.OrmLite.Tests/LoadReferencesJoinTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,20 @@ public void Can_join_on_references_attribute()
row3 = db.LoadSingleById<TABLE_3>(row3.Id);
Assert.That(row3.TableTwoKey, Is.EqualTo(row3.TableTwo.Id));
}

[Test]
public void Can_load_references_with_OrderBy()
{
AddCustomersWithOrders();

var customers = db.LoadSelect<Customer>(q => q.OrderBy(x => x.Name));
var addresses = customers.Select(x => x.PrimaryAddress).ToList();
var orders = customers.SelectMany(x => x.Orders).ToList();

Assert.That(customers.Count, Is.EqualTo(2));
Assert.That(addresses.Count, Is.EqualTo(2));
Assert.That(orders.Count, Is.EqualTo(6));
}
}

[Alias("Table1")]
Expand Down

0 comments on commit 8d328f4

Please sign in to comment.