22 * Copyright (c) ZKEASOFT. All rights reserved.
33 * http://www.zkea.net/licenses */
44
5- using System . Collections . Generic ;
65using Easy ;
6+ using Easy . Constant ;
77using Easy . RepositoryPattern ;
88using Microsoft . EntityFrameworkCore ;
9+ using System . Collections . Generic ;
910using ZKEACMS . Common . Models ;
1011using ZKEACMS . ExtendField ;
1112using ZKEACMS . Layout ;
1213using ZKEACMS . Media ;
14+ using ZKEACMS . Options ;
1315using ZKEACMS . Page ;
1416using ZKEACMS . PendingTask ;
1517using ZKEACMS . Setting ;
@@ -22,9 +24,14 @@ namespace ZKEACMS
2224{
2325 public class CMSDbContext : EasyDbContext
2426 {
25- public CMSDbContext ( DbContextOptions < CMSDbContext > dbContextOptions , IEnumerable < IOnModelCreating > modelCreatings ) : base ( dbContextOptions )
27+ private readonly DatabaseOption _databaseOption ;
28+ public CMSDbContext ( DbContextOptions < CMSDbContext > dbContextOptions ,
29+ IEnumerable < IOnModelCreating > modelCreatings ,
30+ DatabaseOption databaseOption )
31+ : base ( dbContextOptions )
2632 {
2733 ModelCreatings = modelCreatings ;
34+ _databaseOption = databaseOption ;
2835 }
2936
3037 public DbSet < WidgetBasePart > WidgetBasePart { get ; set ; }
@@ -48,5 +55,27 @@ public CMSDbContext(DbContextOptions<CMSDbContext> dbContextOptions, IEnumerable
4855 public DbSet < StyleSheetWidget > StyleSheetWidget { get ; set ; }
4956 public DbSet < VideoWidget > VideoWidget { get ; set ; }
5057 public DbSet < BreadcrumbWidget > BreadcrumbWidget { get ; set ; }
58+
59+ protected override void OnModelCreating ( ModelBuilder modelBuilder )
60+ {
61+ base . OnModelCreating ( modelBuilder ) ;
62+
63+ var tableNamingConverter = new NamingConverter ( _databaseOption . TableNaming ) ;
64+ var columnNamingConverter = new NamingConverter ( _databaseOption . ColumnNaming ) ;
65+ foreach ( var entity in modelBuilder . Model . GetEntityTypes ( ) )
66+ {
67+ if ( tableNamingConverter . Strategy != NameCaseStrategy . None )
68+ {
69+ entity . SetTableName ( tableNamingConverter . ConvertName ( entity . GetTableName ( ) ) ) ;
70+ }
71+ foreach ( var property in entity . GetProperties ( ) )
72+ {
73+ if ( columnNamingConverter . Strategy != NameCaseStrategy . None )
74+ {
75+ property . SetColumnName ( columnNamingConverter . ConvertName ( property . GetColumnName ( ) ) ) ;
76+ }
77+ }
78+ }
79+ }
5180 }
5281}
0 commit comments