@@ -15,42 +15,43 @@ public class SingleRecordBasicTestPage(IMagicDbFactory magic) : TestPageBase
1515 private record NestedItem ( int Value ) ;
1616
1717 [ MagicTable ( "Records" , null ) ]
18- private record Record (
19- [ property : MagicPrimaryKey ]
20- [ property : JsonIgnore ( Condition = JsonIgnoreCondition . WhenWritingDefault ) ]
21- int Id ,
18+ private class Record
19+ {
20+ [ MagicPrimaryKey ( "id" ) ]
21+ public int Id { get ; set ; }
2222
23- string Normal ,
23+ public string ? Normal { get ; set ; }
2424
25- [ property : JsonIgnore ]
26- bool Ignored ,
25+ [ MagicNotMapped ]
26+ public bool Ignored { get ; set ; }
2727
28- [ property : JsonPropertyName ( "Renamed" ) ]
29- char ShouldBeRenamed ,
28+ [ MagicIndex ( "Renamed" ) ]
29+ public char ShouldBeRenamed { get ; set ; }
3030
31- [ property : MagicIndex ]
32- string Index ,
31+ [ MagicIndex ]
32+ public string ? Index { get ; set ; }
3333
34- [ property : MagicIndex ]
35- Guid UniqueIndex ,
34+ [ MagicIndex ]
35+ public Guid UniqueIndex { get ; set ; }
3636
37- DayOfWeek Enum ,
37+ public DayOfWeek Enum { get ; set ; }
3838
39- NestedItem Nested ,
39+ public NestedItem ? Nested { get ; set ; }
4040
41- long LargeNumber )
42- {
43- public static Record Sample => new Record (
44- Id : 12 ,
45- Normal : "Norm" ,
46- Ignored : true ,
47- ShouldBeRenamed : 'R' ,
48- Index : "I" ,
49- UniqueIndex : Guid . Parse ( "633A97D2-0C92-4C68-883B-364F94AD6030" ) ,
50- Enum : DayOfWeek . Sunday ,
51- Nested : new ( 1234 ) ,
52- LargeNumber : 9007199254740991 ) ;
41+ public long LargeNumber { get ; set ; }
5342 }
43+ static Record NewSample => new Record ( )
44+ {
45+ Id = 12 ,
46+ Normal = "Norm" ,
47+ Ignored = true ,
48+ ShouldBeRenamed = 'R' ,
49+ Index = "I" ,
50+ UniqueIndex = Guid . Parse ( "633A97D2-0C92-4C68-883B-364F94AD6030" ) ,
51+ Enum = DayOfWeek . Sunday ,
52+ Nested = new ( 1234 ) ,
53+ LargeNumber = 9007199254740991
54+ } ;
5455
5556 public async Task < string > Add ( )
5657 {
@@ -60,7 +61,7 @@ public async Task<string> Add()
6061 Version = 1 ,
6162 StoreSchemas = [ SchemaHelper . GetStoreSchema < Record > ( null , false ) ]
6263 } ) ;
63- var id = await database . AddAsync < Record , int > ( Record . Sample ) ;
64+ var id = await database . AddAsync < Record , int > ( NewSample ) ;
6465 return id . ToString ( ) ;
6566 }
6667
@@ -72,8 +73,8 @@ public async Task<string> Delete()
7273 Version = 1 ,
7374 StoreSchemas = [ SchemaHelper . GetStoreSchema < Record > ( null , false ) ]
7475 } ) ;
75- _ = await database . AddAsync < Record , int > ( Record . Sample ) ;
76- await database . DeleteAsync ( Record . Sample ) ;
76+ _ = await database . AddAsync < Record , int > ( NewSample ) ;
77+ await database . DeleteAsync ( NewSample ) ;
7778 return "OK" ;
7879 }
7980
@@ -85,8 +86,11 @@ public async Task<string> Update()
8586 Version = 1 ,
8687 StoreSchemas = [ SchemaHelper . GetStoreSchema < Record > ( null , false ) ]
8788 } ) ;
88- _ = await database . AddAsync < Record , int > ( Record . Sample ) ;
89- var count = await database . UpdateAsync ( Record . Sample with { Normal = "Updated" } ) ;
89+ _ = await database . AddAsync < Record , int > ( NewSample ) ;
90+
91+ var updated = NewSample ;
92+ updated . Normal = "Updated" ;
93+ var count = await database . UpdateAsync ( updated ) ;
9094 return count . ToString ( ) ;
9195 }
9296
@@ -98,8 +102,8 @@ public async Task<string> GetById()
98102 Version = 1 ,
99103 StoreSchemas = [ SchemaHelper . GetStoreSchema < Record > ( null , false ) ]
100104 } ) ;
101- var id = await database . AddAsync < Record , int > ( Record . Sample ) ;
102- var result = await database . GetByIdAsync < Record , int > ( id ) ;
105+ var id = await database . AddAsync < Record , int > ( NewSample ) ;
106+ var result = await database . GetByIdAsync < Record > ( id ) ;
103107 return result . Normal ;
104108 }
105109
@@ -111,7 +115,7 @@ public async Task<string> GetAll()
111115 Version = 1 ,
112116 StoreSchemas = [ SchemaHelper . GetStoreSchema < Record > ( null , false ) ]
113117 } ) ;
114- _ = await database . AddAsync < Record , int > ( Record . Sample ) ;
118+ _ = await database . AddAsync < Record , int > ( NewSample ) ;
115119 var result = await database . GetAllAsync < Record > ( ) ;
116120 return JsonSerializer . Serialize ( result ) ;
117121 }
0 commit comments