22using System . Linq ;
33using NUnit . Framework ;
44using ServiceStack . Common . Tests . Models ;
5+ using ServiceStack . DataAnnotations ;
56using ServiceStack . Text ;
67
78namespace ServiceStack . OrmLite . Tests
@@ -92,7 +93,30 @@ public void Lists_Of_Guids_Are_Formatted_Correctly()
9293 }
9394 }
9495
95- }
96+ [ Test ]
97+ public void Can_insert_Contact_with_Complex_NameDetail ( )
98+ {
99+ using ( var db = OpenDbConnection ( ) )
100+ {
101+ db . DropAndCreateTable < Contact > ( ) ;
102+
103+ var contact = new Contact
104+ {
105+ FullName = new NameDetail ( "Test" , "Contact" ) ,
106+ Email = "test@email.com" ,
107+ Age = 10
108+ } ;
109+ db . Save ( contact ) ;
110+
111+ var dbContact = db . Single < Contact > ( q => q . Email == contact . Email ) ;
112+
113+ Assert . That ( dbContact . Email , Is . EqualTo ( contact . Email ) ) ;
114+ Assert . That ( dbContact . Age , Is . EqualTo ( contact . Age ) ) ;
115+ Assert . That ( dbContact . FullName . First , Is . EqualTo ( contact . FullName . First ) ) ;
116+ Assert . That ( dbContact . FullName . Last , Is . EqualTo ( contact . FullName . Last ) ) ;
117+ }
118+ }
119+ }
96120
97121 public class WithAListOfGuids
98122 {
@@ -102,4 +126,57 @@ public class WithAListOfGuids
102126
103127 public IEnumerable < Guid > TheGuids { get ; set ; }
104128 }
129+
130+ public class Contact
131+ {
132+ public Contact ( )
133+ {
134+ Tags = new List < AvailableTags > ( ) ;
135+ FullName = new NameDetail ( ) ;
136+ }
137+
138+ [ AutoIncrement ]
139+ public int Id { get ; set ; }
140+
141+ public string Email { get ; set ; }
142+ public int Age { get ; set ; }
143+ public List < AvailableTags > Tags { get ; set ; }
144+
145+ public NameDetail FullName { get ; set ; }
146+
147+ [ DataAnnotations . Ignore ]
148+ public string Name
149+ {
150+ get { return FullName . ToString ( ) ; }
151+ }
152+ }
153+
154+ public class NameDetail
155+ {
156+ public NameDetail ( ) { }
157+
158+ public NameDetail ( string first , string last )
159+ {
160+ First = first ;
161+ Last = last ;
162+ }
163+
164+ public string First { get ; set ; }
165+
166+ public string Last { get ; set ; }
167+
168+ public override string ToString ( )
169+ {
170+ return string . Format ( "{0} {1}" , First , Last ) . Trim ( ) ;
171+ }
172+ }
173+
174+ public enum AvailableTags
175+ {
176+ other ,
177+ glam ,
178+ hiphop ,
179+ grunge ,
180+ funk
181+ }
105182}
0 commit comments