specimen
specimen

Reputation: 1765

ServiceStack OrmLite SelectMulti same table

This is a bit related to this question: Joining same table multiple times in ServiceStack.OrmLite

TableAlias works with Select, but not SelectMulti.

Example:

var query = db.From<Department>(db.TableAlias("main"))
  .Where(main => main.DepLevel == 3)
  .Join<Department>((main, sub) => sub.DepParentNo == main.DepNo, db.TableAlias("sub"));

Now var rows = db.Select(query); works, but this crashes:

var queryResults = db.SelectMulti<Department, Department>(query);

I've confirmed that when using db.Select the LastCommandText correctly aliases all three tables. However it probably doesn't do that with SelectMulti.

The error message is as expected: The column prefix 'Department' does not match with a table name or alias name used in the query.

Upvotes: 2

Views: 150

Answers (1)

specimen
specimen

Reputation: 1765

Answering my own question here:

There's an example in SS's source code:

AssertTupleResults(db.SelectMulti<Sale, ContactIssue, ContactIssue>(q, 
    new[] { "Sale.*", "buyer.*", "seller.*" }));

https://github.com/ServiceStack/ServiceStack.OrmLite/blob/1ba40ef4b77d9ae792a268f1683c51960d4476d6/tests/ServiceStack.OrmLite.Tests/Issues/MultipleSelfJoinsWithJoinAliases.cs#L216

So the expression is now:

var queryResults = db.SelectMulti<Department, Department>(query, 
    new[] { "main.*", "sub.*" });

Upvotes: 2

Related Questions