File tree Expand file tree Collapse file tree 3 files changed +60
-2
lines changed Expand file tree Collapse file tree 3 files changed +60
-2
lines changed Original file line number Diff line number Diff line change 1+ using System . IO ;
2+ using Xunit ;
3+
4+ namespace LiteDB . Tests . Database ;
5+
6+ public class Writing_While_Reading_Test
7+ {
8+ [ Fact ]
9+ public void Test ( )
10+ {
11+ using var f = new TempFile ( ) ;
12+ using ( var db = new LiteDatabase ( f . Filename ) )
13+ {
14+ var col = db . GetCollection < MyClass > ( "col" ) ;
15+ col . Insert ( new MyClass { Name = "John" , Description = "Doe" } ) ;
16+ col . Insert ( new MyClass { Name = "Joana" , Description = "Doe" } ) ;
17+ col . Insert ( new MyClass { Name = "Doe" , Description = "Doe" } ) ;
18+ }
19+
20+
21+ using ( var db = new LiteDatabase ( f . Filename ) )
22+ {
23+ var col = db . GetCollection < MyClass > ( "col" ) ;
24+ foreach ( var item in col . FindAll ( ) )
25+ {
26+ item . Description += " Changed" ;
27+ col . Update ( item ) ;
28+ }
29+
30+ db . Commit ( ) ;
31+ }
32+
33+
34+ using ( var db = new LiteDatabase ( f . Filename ) )
35+ {
36+ var col = db . GetCollection < MyClass > ( "col" ) ;
37+ foreach ( var item in col . FindAll ( ) )
38+ {
39+ Assert . EndsWith ( "Changed" , item . Description ) ;
40+ }
41+ }
42+ }
43+
44+ class MyClass
45+ {
46+ public int Id { get ; set ; }
47+
48+ public string Name { get ; set ; }
49+
50+ public string Description { get ; set ; }
51+ }
52+ }
Original file line number Diff line number Diff line change @@ -30,8 +30,13 @@ internal EntityMapper GetEntityMapper(Type type)
3030 {
3131 this . BuildEntityMapper ( mapper ) ;
3232 }
33- cts . Cancel ( ) ;
34- cts . Dispose ( ) ;
33+ else
34+ {
35+ if ( ! _entities . TryGetValue ( type , out mapper ) )
36+ {
37+ throw new LiteException ( LiteException . MAPPER_NOT_FOUND , $ "EntityMapper for type { type } was not found.") ;
38+ }
39+ }
3540
3641 return mapper ;
3742 }
Original file line number Diff line number Diff line change @@ -58,6 +58,7 @@ public class LiteException : Exception
5858 public const int INVALID_PASSWORD = 217 ;
5959 public const int ILLEGAL_DESERIALIZATION_TYPE = 218 ;
6060 public const int ENTITY_INITIALIZATION_FAILED = 219 ;
61+ public const int MAPPER_NOT_FOUND = 220 ;
6162
6263 public const int INVALID_DATAFILE_STATE = 999 ;
6364
You can’t perform that action at this time.
0 commit comments