This repository has been archived by the owner on Dec 24, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
93 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
tests/ServiceStack.OrmLite.Tests/Issues/DynamicDataIssue.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data; | ||
using NUnit.Framework; | ||
using ServiceStack.DataAnnotations; | ||
using ServiceStack.Text; | ||
|
||
namespace ServiceStack.OrmLite.Tests.Issues | ||
{ | ||
public class ParentTbl | ||
{ | ||
[AutoIncrement] | ||
public long Id { get; set; } | ||
|
||
public DateTime? DateMarried { get; set; } | ||
|
||
[Reference] | ||
public List<ChildTbl> Childs { get; set; } = new List<ChildTbl>(); | ||
|
||
public DateTime? DateOfBirth { get; set; } | ||
} | ||
|
||
public class ChildTbl | ||
{ | ||
[AutoIncrement] | ||
public long Id { get; set; } | ||
|
||
[References(typeof(ParentTbl))] | ||
public long ParentId { get; set; } | ||
|
||
public DateTime? DateOfDeath { get; set; } | ||
} | ||
|
||
|
||
public class DynamicDataIssue : OrmLiteTestBase | ||
{ | ||
private static void InitTables(IDbConnection db) | ||
{ | ||
db.DropTable<ChildTbl>(); | ||
db.DropTable<ParentTbl>(); | ||
db.CreateTable<ParentTbl>(); | ||
db.CreateTable<ChildTbl>(); | ||
} | ||
|
||
[Test] | ||
public void Can_select_null_DateTime_in_nullable_Tuple() | ||
{ | ||
var date = new DateTime(2000,1,1); | ||
|
||
using (var db = OpenDbConnection()) | ||
{ | ||
InitTables(db); | ||
|
||
db.Insert(new ParentTbl { DateOfBirth = date }); | ||
db.Insert(new ParentTbl { DateOfBirth = null }); | ||
|
||
db.Select<ParentTbl>(); | ||
db.Select<(int, DateTime?)>(db.From<ParentTbl>()); | ||
db.Select<(int, DateTime?)>(db.From<ParentTbl>().Select(x => new { x.Id, x.DateOfBirth })); | ||
db.Select<(int, DateTime)>(db.From<ParentTbl>().Select(x => new { x.Id, x.DateOfBirth })); | ||
} | ||
} | ||
|
||
[Test] | ||
public void Complex_example() | ||
{ | ||
using (var db = OpenDbConnection()) | ||
{ | ||
InitTables(db); | ||
|
||
var parentTbl = new ParentTbl { DateMarried = DateTime.Today }; | ||
parentTbl.Id = db.Insert(parentTbl, selectIdentity:true); | ||
db.Insert(new ChildTbl { ParentId = parentTbl.Id, DateOfDeath = null }); | ||
|
||
var q = db.From<ChildTbl>() | ||
.RightJoin<ChildTbl, ParentTbl>((c, p) => c.ParentId == p.Id || c.Id == null) | ||
.GroupBy<ParentTbl>((p) => new { p.Id }) | ||
.Select<ChildTbl, ParentTbl>((c, p) => new { p.Id, MaxKeyValuePeriodEnd = Sql.Max(c.DateOfDeath) }); | ||
|
||
var theSqlStatement = q.ToSelectStatement(); | ||
|
||
theSqlStatement.Print(); | ||
} | ||
} | ||
|
||
} | ||
} |
c90537e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Complex example test case won't actually trigger the db call will it? But thanks as always for prompt fixes!