11using NUnit . Framework ;
22using ServiceStack . DataAnnotations ;
3- using ServiceStack . Logging ;
3+ using ServiceStack . Text ;
44
55namespace ServiceStack . OrmLite . Tests . Issues
66{
@@ -35,8 +35,6 @@ public class SchemaTable2
3535 [ Test ]
3636 public void Can_join_on_table_with_schemas ( )
3737 {
38- LogManager . LogFactory = new ConsoleLogFactory ( debugEnabled : true ) ;
39-
4038 using ( var db = OpenDbConnection ( ) )
4139 {
4240 db . DropAndCreateTable < SchemaTable1 > ( ) ;
@@ -67,5 +65,71 @@ public void Can_join_on_table_with_schemas()
6765 Assert . That ( rows . Count , Is . EqualTo ( 1 ) ) ;
6866 }
6967 }
68+
69+ [ Test ]
70+ public void Can_query_with_Schema_and_alias_attributes ( )
71+ {
72+ using ( var db = OpenDbConnection ( ) )
73+ {
74+ db . DropAndCreateTable < Section > ( ) ;
75+ db . DropAndCreateTable < Page > ( ) ;
76+
77+ db . Save ( new Page {
78+ ReportSectionId = 1 ,
79+ SectionId = 1 ,
80+ } , references : true ) ;
81+ db . Save ( new Page {
82+ ReportSectionId = 2 ,
83+ SectionId = 2 ,
84+ } , references : true ) ;
85+ db . Save ( new Section {
86+ Id = 1 ,
87+ ReportSectionId = 1 ,
88+ Name = "Name1" ,
89+ ReportId = 15 ,
90+ } , references : true ) ;
91+
92+ var query = db . From < Section > ( )
93+ . LeftJoin < Section , Page > ( ( s , p ) => s . Id == p . SectionId )
94+ . Where < Section > ( s => s . ReportId == 15 ) ;
95+
96+ var results = db . Select ( query ) ;
97+ db . GetLastSql ( ) . Print ( ) ;
98+
99+ results . PrintDump ( ) ;
100+
101+ Assert . That ( results . Count , Is . EqualTo ( 1 ) ) ;
102+ Assert . That ( results [ 0 ] . Name , Is . EqualTo ( "Name1" ) ) ;
103+ }
104+ }
105+ }
106+
107+ [ Schema ( "Schema" ) ]
108+ [ Alias ( "PageAlias" ) ]
109+ public class Page
110+ {
111+ [ AutoIncrement ]
112+ public int Id { get ; set ; }
113+
114+ [ Alias ( "ReportSectionIdAlias" ) ]
115+ public int ReportSectionId { get ; set ; }
116+
117+ [ Alias ( "SectionIdAlias" ) ]
118+ public int SectionId { get ; set ; }
119+ }
120+
121+ [ Schema ( "Schema" ) ]
122+ [ Alias ( "SectionAlias" ) ]
123+ public class Section
124+ {
125+ public int Id { get ; set ; }
126+
127+ [ Alias ( "ReportSectionIdAlias" ) ]
128+ public int ReportSectionId { get ; set ; }
129+
130+ [ Alias ( "NameAlias" ) ]
131+ public string Name { get ; set ; }
132+ [ Alias ( "ReportIdAlias" ) ]
133+ public int ReportId { get ; set ; }
70134 }
71135}
0 commit comments