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

Commit 2f61de9

Browse files
committed
Add select custom json result in Table type test
1 parent 8497122 commit 2f61de9

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/ServiceStack.OrmLite.Tests/Issues/MultipleSelfJoinsWithTableAliases.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,5 +350,35 @@ public async Task Can_select_custom_result_with_json_type()
350350
Assert.That(result.FirstName, Is.Not.Null);
351351
Assert.That(result.LastName, Is.Not.Null);
352352
}
353+
354+
public class ContactIssueJson
355+
{
356+
public string Json { get; set; }
357+
}
358+
359+
[Test]
360+
public async Task Can_select_custom_json_result_in_Table_type()
361+
{
362+
if ((Dialect & Dialect.AnyPostgreSql) != Dialect)
363+
return;
364+
365+
using var db = await OpenDbConnectionAsync();
366+
var tenantId = Guid.NewGuid();
367+
var sale = PopulateData(db, tenantId);
368+
369+
var q = db.From<Sale>()
370+
.LeftJoin<ContactIssue>((s, c) => s.SellerId == c.Id, db.TableAlias("seller"))
371+
.LeftJoin<ContactIssue>((s, c) => s.BuyerId == c.Id, db.TableAlias("buyer"))
372+
.GroupBy<Sale, ContactIssue>((s,c) => new { SaleId = s.Id, BuyerId = Sql.TableAlias(c.Id, "buyer") })
373+
.Select<Sale,ContactIssue>((s,c) => new {
374+
s,
375+
buyer = Sql.TableAlias(c, "buyer"),
376+
Json = Sql.Custom($"json_agg(seller)"),
377+
});
378+
379+
var results = db.Select<Tuple<Sale, ContactIssue, ContactIssueJson>>(q);
380+
Assert.That(results[0].Item3.Json, Does.StartWith("["));
381+
}
382+
353383
}
354384
}

0 commit comments

Comments
 (0)