1
1
using System ;
2
2
using Microsoft . EntityFrameworkCore ;
3
+ using VirtoCommerce . Platform . Data . Extensions ;
3
4
using VirtoCommerce . Platform . Data . Infrastructure ;
4
5
using VirtoCommerce . Platform . Data . Localizations ;
5
6
using VirtoCommerce . Platform . Data . Model ;
@@ -8,10 +9,13 @@ namespace VirtoCommerce.Platform.Data.Repositories
8
9
{
9
10
public class PlatformDbContext : DbContextBase
10
11
{
11
- [ Obsolete ( "Use IdLength" , DiagnosticId = "VC0009" , UrlFormat = "https://docs.virtocommerce.org/products/products-virto3-versions" ) ]
12
+ [ Obsolete ( "Use Length128 or IdLength" , DiagnosticId = "VC0009" , UrlFormat = "https://docs.virtocommerce.org/products/products-virto3-versions" ) ]
12
13
protected const int _idLength128 = 128 ;
13
14
15
+ [ Obsolete ( "Use Length64 or UserNameLength" , DiagnosticId = "VC0010" , UrlFormat = "https://docs.virtocommerce.org/products/products-virto3-versions" ) ]
14
16
protected const int _idLength64 = 64 ;
17
+
18
+ [ Obsolete ( "Use Length2048" , DiagnosticId = "VC0010" , UrlFormat = "https://docs.virtocommerce.org/products/products-virto3-versions" ) ]
15
19
protected const int _idLength2048 = 2048 ;
16
20
17
21
public PlatformDbContext ( DbContextOptions < PlatformDbContext > options )
@@ -29,108 +33,81 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
29
33
base . OnModelCreating ( modelBuilder ) ;
30
34
31
35
#region Change logging
32
- modelBuilder . Entity < OperationLogEntity > ( ) . ToTable ( "PlatformOperationLog" ) . HasKey ( x => x . Id ) ;
33
- modelBuilder . Entity < OperationLogEntity > ( ) . Property ( x => x . Id ) . HasMaxLength ( IdLength ) . ValueGeneratedOnAdd ( ) ;
34
- modelBuilder . Entity < OperationLogEntity > ( ) . Property ( x => x . CreatedBy ) . HasMaxLength ( _idLength64 ) ;
35
- modelBuilder . Entity < OperationLogEntity > ( ) . Property ( x => x . ModifiedBy ) . HasMaxLength ( _idLength64 ) ;
36
- modelBuilder . Entity < OperationLogEntity > ( ) . Property ( x => x . Detail ) . HasMaxLength ( _idLength2048 ) ;
37
- modelBuilder . Entity < OperationLogEntity > ( ) . HasIndex ( x => new { x . ObjectType , x . ObjectId } )
36
+ modelBuilder . Entity < OperationLogEntity > ( ) . ToAuditableEntityTable ( "PlatformOperationLog" ) ;
37
+ modelBuilder . Entity < OperationLogEntity > ( )
38
+ . HasIndex ( x => new { x . ObjectType , x . ObjectId } )
38
39
. IsUnique ( false )
39
40
. HasDatabaseName ( "IX_OperationLog_ObjectType_ObjectId" ) ;
40
41
#endregion
41
42
42
43
#region Settings
43
- modelBuilder . Entity < SettingEntity > ( ) . ToTable ( "PlatformSetting" ) . HasKey ( x => x . Id ) ;
44
- modelBuilder . Entity < SettingEntity > ( ) . Property ( x => x . Id ) . HasMaxLength ( IdLength ) . ValueGeneratedOnAdd ( ) ;
45
- modelBuilder . Entity < SettingEntity > ( ) . Property ( x => x . CreatedBy ) . HasMaxLength ( _idLength64 ) ;
46
- modelBuilder . Entity < SettingEntity > ( ) . Property ( x => x . ModifiedBy ) . HasMaxLength ( _idLength64 ) ;
47
- modelBuilder . Entity < SettingEntity > ( ) . HasIndex ( x => new { x . ObjectType , x . ObjectId } )
44
+ modelBuilder . Entity < SettingEntity > ( ) . ToAuditableEntityTable ( "PlatformSetting" ) ;
45
+ modelBuilder . Entity < SettingEntity > ( )
46
+ . HasIndex ( x => new { x . ObjectType , x . ObjectId } )
48
47
. IsUnique ( false )
49
48
. HasDatabaseName ( "IX_ObjectType_ObjectId" ) ;
50
49
51
- modelBuilder . Entity < SettingValueEntity > ( ) . ToTable ( "PlatformSettingValue" ) . HasKey ( x => x . Id ) ;
52
- modelBuilder . Entity < SettingValueEntity > ( ) . Property ( x => x . Id ) . HasMaxLength ( IdLength ) . ValueGeneratedOnAdd ( ) ;
53
- modelBuilder . Entity < SettingValueEntity > ( ) . Property ( x => x . CreatedBy ) . HasMaxLength ( _idLength64 ) ;
54
- modelBuilder . Entity < SettingValueEntity > ( ) . Property ( x => x . ModifiedBy ) . HasMaxLength ( _idLength64 ) ;
55
-
56
- modelBuilder . Entity < SettingValueEntity > ( ) . HasOne ( x => x . Setting )
50
+ modelBuilder . Entity < SettingValueEntity > ( ) . ToAuditableEntityTable ( "PlatformSettingValue" ) ;
51
+ modelBuilder . Entity < SettingValueEntity > ( ) . Property ( x => x . DecimalValue ) . HasColumnType ( "decimal(18,5)" ) ;
52
+ modelBuilder . Entity < SettingValueEntity > ( )
53
+ . HasOne ( x => x . Setting )
57
54
. WithMany ( x => x . SettingValues )
58
55
. HasForeignKey ( x => x . SettingId )
59
56
. OnDelete ( DeleteBehavior . Cascade )
60
57
. IsRequired ( ) ;
61
-
62
- modelBuilder . Entity < SettingValueEntity > ( )
63
- . Property ( x => x . DecimalValue )
64
- . HasColumnType ( "decimal(18,5)" ) ;
65
-
66
58
#endregion
67
59
68
60
#region Localization
69
- modelBuilder . Entity < LocalizedItemEntity > ( ) . ToTable ( "PlatformLocalizedItem" ) . HasKey ( x => x . Id ) ;
70
- modelBuilder . Entity < LocalizedItemEntity > ( ) . Property ( x => x . Id ) . HasMaxLength ( IdLength ) . ValueGeneratedOnAdd ( ) ;
71
- modelBuilder . Entity < LocalizedItemEntity > ( ) . Property ( x => x . CreatedBy ) . HasMaxLength ( _idLength64 ) ;
72
- modelBuilder . Entity < LocalizedItemEntity > ( ) . Property ( x => x . ModifiedBy ) . HasMaxLength ( _idLength64 ) ;
61
+ modelBuilder . Entity < LocalizedItemEntity > ( ) . ToAuditableEntityTable ( "PlatformLocalizedItem" ) ;
73
62
modelBuilder . Entity < LocalizedItemEntity > ( )
74
- . HasIndex ( x => new { x . Name , x . Alias } )
75
- . IsUnique ( false )
76
- . HasDatabaseName ( "IX_PlatformLocalizedItem_Name_Alias" ) ;
63
+ . HasIndex ( x => new { x . Name , x . Alias } )
64
+ . IsUnique ( false )
65
+ . HasDatabaseName ( "IX_PlatformLocalizedItem_Name_Alias" ) ;
77
66
#endregion
78
67
79
68
#region Dynamic Properties
80
-
81
- modelBuilder . Entity < DynamicPropertyEntity > ( ) . ToTable ( "PlatformDynamicProperty" ) . HasKey ( x => x . Id ) ;
82
- modelBuilder . Entity < DynamicPropertyEntity > ( ) . Property ( x => x . Id ) . HasMaxLength ( IdLength ) . ValueGeneratedOnAdd ( ) ;
83
- modelBuilder . Entity < DynamicPropertyEntity > ( ) . Property ( x => x . CreatedBy ) . HasMaxLength ( _idLength64 ) ;
84
- modelBuilder . Entity < DynamicPropertyEntity > ( ) . Property ( x => x . ModifiedBy ) . HasMaxLength ( _idLength64 ) ;
85
- modelBuilder . Entity < DynamicPropertyEntity > ( ) . HasIndex ( x => new { x . ObjectType , x . Name } )
69
+ modelBuilder . Entity < DynamicPropertyEntity > ( ) . ToAuditableEntityTable ( "PlatformDynamicProperty" ) ;
70
+ modelBuilder . Entity < DynamicPropertyEntity > ( )
71
+ . HasIndex ( x => new { x . ObjectType , x . Name } )
86
72
. HasDatabaseName ( "IX_PlatformDynamicProperty_ObjectType_Name" )
87
- . IsUnique ( true ) ;
73
+ . IsUnique ( ) ;
88
74
89
- modelBuilder . Entity < DynamicPropertyNameEntity > ( ) . ToTable ( "PlatformDynamicPropertyName" ) . HasKey ( x => x . Id ) ;
90
- modelBuilder . Entity < DynamicPropertyNameEntity > ( ) . Property ( x => x . Id ) . HasMaxLength ( IdLength ) . ValueGeneratedOnAdd ( ) ;
91
- modelBuilder . Entity < DynamicPropertyNameEntity > ( ) . Property ( x => x . CreatedBy ) . HasMaxLength ( _idLength64 ) ;
92
- modelBuilder . Entity < DynamicPropertyNameEntity > ( ) . Property ( x => x . ModifiedBy ) . HasMaxLength ( _idLength64 ) ;
93
- modelBuilder . Entity < DynamicPropertyNameEntity > ( ) . HasOne ( x => x . Property )
75
+ modelBuilder . Entity < DynamicPropertyNameEntity > ( ) . ToAuditableEntityTable ( "PlatformDynamicPropertyName" ) ;
76
+ modelBuilder . Entity < DynamicPropertyNameEntity > ( )
77
+ . HasOne ( x => x . Property )
94
78
. WithMany ( x => x . DisplayNames )
95
79
. HasForeignKey ( x => x . PropertyId )
96
80
. OnDelete ( DeleteBehavior . Cascade ) ;
97
81
modelBuilder . Entity < DynamicPropertyNameEntity > ( )
98
82
. HasIndex ( x => new { x . PropertyId , x . Locale , x . Name } )
99
83
. HasDatabaseName ( "IX_PlatformDynamicPropertyName_PropertyId_Locale_Name" )
100
- . IsUnique ( true ) ;
84
+ . IsUnique ( ) ;
101
85
102
- modelBuilder . Entity < DynamicPropertyDictionaryItemEntity > ( ) . ToTable ( "PlatformDynamicPropertyDictionaryItem" ) . HasKey ( x => x . Id ) ;
103
- modelBuilder . Entity < DynamicPropertyDictionaryItemEntity > ( ) . Property ( x => x . Id ) . HasMaxLength ( IdLength ) . ValueGeneratedOnAdd ( ) ;
104
- modelBuilder . Entity < DynamicPropertyDictionaryItemEntity > ( ) . Property ( x => x . CreatedBy ) . HasMaxLength ( _idLength64 ) ;
105
- modelBuilder . Entity < DynamicPropertyDictionaryItemEntity > ( ) . Property ( x => x . ModifiedBy ) . HasMaxLength ( _idLength64 ) ;
106
- modelBuilder . Entity < DynamicPropertyDictionaryItemEntity > ( ) . HasOne ( x => x . Property )
86
+ modelBuilder . Entity < DynamicPropertyDictionaryItemEntity > ( ) . ToAuditableEntityTable ( "PlatformDynamicPropertyDictionaryItem" ) ;
87
+ modelBuilder . Entity < DynamicPropertyDictionaryItemEntity > ( )
88
+ . HasOne ( x => x . Property )
107
89
. WithMany ( x => x . DictionaryItems )
108
90
. HasForeignKey ( x => x . PropertyId )
109
91
. OnDelete ( DeleteBehavior . Cascade ) ;
110
92
modelBuilder . Entity < DynamicPropertyDictionaryItemEntity > ( )
111
93
. HasIndex ( x => new { x . PropertyId , x . Name } )
112
94
. HasDatabaseName ( "IX_PlatformDynamicPropertyDictionaryItem_PropertyId_Name" )
113
- . IsUnique ( true ) ;
95
+ . IsUnique ( ) ;
114
96
115
- modelBuilder . Entity < DynamicPropertyDictionaryItemNameEntity > ( ) . ToTable ( "PlatformDynamicPropertyDictionaryItemName" ) . HasKey ( x => x . Id ) ;
116
- modelBuilder . Entity < DynamicPropertyDictionaryItemNameEntity > ( ) . Property ( x => x . Id ) . HasMaxLength ( IdLength ) . ValueGeneratedOnAdd ( ) ;
117
- modelBuilder . Entity < DynamicPropertyDictionaryItemNameEntity > ( ) . Property ( x => x . CreatedBy ) . HasMaxLength ( _idLength64 ) ;
118
- modelBuilder . Entity < DynamicPropertyDictionaryItemNameEntity > ( ) . Property ( x => x . ModifiedBy ) . HasMaxLength ( _idLength64 ) ;
119
- modelBuilder . Entity < DynamicPropertyDictionaryItemNameEntity > ( ) . HasOne ( x => x . DictionaryItem )
97
+ modelBuilder . Entity < DynamicPropertyDictionaryItemNameEntity > ( ) . ToAuditableEntityTable ( "PlatformDynamicPropertyDictionaryItemName" ) ;
98
+ modelBuilder . Entity < DynamicPropertyDictionaryItemNameEntity > ( )
99
+ . HasOne ( x => x . DictionaryItem )
120
100
. WithMany ( x => x . DisplayNames )
121
101
. HasForeignKey ( x => x . DictionaryItemId )
122
102
. OnDelete ( DeleteBehavior . Cascade ) ;
123
103
modelBuilder . Entity < DynamicPropertyDictionaryItemNameEntity > ( )
124
104
. HasIndex ( x => new { x . DictionaryItemId , x . Locale , x . Name } )
125
105
. HasDatabaseName ( "IX_PlatformDynamicPropertyDictionaryItemName_DictionaryItemId_Locale_Name" )
126
- . IsUnique ( true ) ;
127
-
106
+ . IsUnique ( ) ;
128
107
#endregion
129
108
130
109
#region Raw license
131
- modelBuilder . Entity < RawLicenseEntity > ( ) . ToTable ( "RawLicense" ) . HasKey ( x => x . Id ) ;
132
- modelBuilder . Entity < RawLicenseEntity > ( ) . Property ( x => x . Id ) . HasMaxLength ( IdLength ) . ValueGeneratedOnAdd ( ) ;
133
- modelBuilder . Entity < RawLicenseEntity > ( ) . Property ( x => x . Data ) ;
110
+ modelBuilder . Entity < RawLicenseEntity > ( ) . ToEntityTable ( "RawLicense" ) ;
134
111
#endregion
135
112
}
136
113
}
0 commit comments