This repository was archived by the owner on Apr 15, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +66
-4
lines changed Expand file tree Collapse file tree 3 files changed +66
-4
lines changed Original file line number Diff line number Diff line change 89
89
<Compile Include =" Models\TestNullableProperty.cs" />
90
90
<Compile Include =" Models\TestOther.cs" />
91
91
<Compile Include =" Models\TestOverride.cs" />
92
+ <Compile Include =" PerformanceTest.cs" />
92
93
<Compile Include =" QueryTestGroupBy.cs" />
93
94
<Compile Include =" QueryTestHaving.cs" />
94
95
<Compile Include =" QueryTestJoins.cs" />
Original file line number Diff line number Diff line change
1
+ using DataCore . Test . Models ;
2
+ using NUnit . Framework ;
3
+
4
+ namespace DataCore . Test
5
+ {
6
+ [ TestFixture ]
7
+ public class PerformanceTest
8
+ {
9
+ [ Test ]
10
+ public void TimedSelect ( )
11
+ {
12
+ using ( var connection = TestHelper . GetConnectionFor ( TestHelper . DatabaseType . Sqlite , "Data Source=:memory:" ) )
13
+ {
14
+ var db = TestHelper . GetDatabaseFor ( TestHelper . DatabaseType . Sqlite , connection ) ;
15
+
16
+ db . CreateTableIfNotExists < TestClass > ( ) ;
17
+ db . Insert ( TestHelper . GetNewTestClass ( ) ) ;
18
+
19
+ for ( int i = 0 ; i < 100000 ; i ++ )
20
+ {
21
+ db . SelectById < TestClass > ( 1 ) ;
22
+ }
23
+
24
+ connection . Close ( ) ;
25
+ }
26
+ }
27
+
28
+ [ Test ]
29
+ public void TimedSelectWhere ( )
30
+ {
31
+ using ( var connection = TestHelper . GetConnectionFor ( TestHelper . DatabaseType . Sqlite , "Data Source=:memory:" ) )
32
+ {
33
+ var db = TestHelper . GetDatabaseFor ( TestHelper . DatabaseType . Sqlite , connection ) ;
34
+
35
+ db . CreateTableIfNotExists < TestClass > ( ) ;
36
+ db . Insert ( TestHelper . GetNewTestClass ( ) ) ;
37
+
38
+ for ( int i = 0 ; i < 100000 ; i ++ )
39
+ {
40
+ db . Select < TestClass > ( t => t . Id == 1 ) ;
41
+ }
42
+
43
+ connection . Close ( ) ;
44
+ }
45
+ }
46
+ }
47
+ }
Original file line number Diff line number Diff line change 7
7
8
8
namespace DataCore
9
9
{
10
- public class TableDefinition
10
+ public sealed class TableDefinition
11
11
{
12
- public string Name { get ; set ; }
13
- public FieldDefinition IdField { get ; set ; }
14
- public List < FieldDefinition > Fields { get ; set ; }
12
+ private static readonly Dictionary < Type , TableDefinition > Definitions = new Dictionary < Type , TableDefinition > ( ) ;
13
+
14
+ public string Name { get ; }
15
+ public FieldDefinition IdField { get ; }
16
+ public List < FieldDefinition > Fields { get ; }
15
17
16
18
public TableDefinition ( Type type )
17
19
{
20
+ if ( Definitions . ContainsKey ( type ) )
21
+ {
22
+ var definition = Definitions [ type ] ;
23
+ Name = definition . Name ;
24
+ IdField = definition . IdField ;
25
+ Fields = definition . Fields ;
26
+
27
+ return ;
28
+ }
29
+
18
30
Name = GetTableName ( type ) ;
19
31
IdField = GetIdFieldForType ( type ) ;
20
32
Fields = GetPropertiesForType ( type ) . Select ( GetFieldForProperty ) . ToList ( ) ;
33
+
34
+ Definitions . Add ( type , this ) ;
21
35
}
22
36
23
37
private IEnumerable < PropertyInfo > GetPropertiesForType ( Type type )
You can’t perform that action at this time.
0 commit comments