@@ -55,9 +55,7 @@ public EntityContext Generate(GeneratorOptions options, DatabaseModel databaseMo
5555 entityContext . ContextNamespace = contextNamespace ;
5656 entityContext . ContextBaseClass = contextBaseClass ;
5757
58- var tables = databaseModel . Tables ;
59-
60- foreach ( var table in tables )
58+ foreach ( var table in databaseModel . Tables )
6159 {
6260 if ( IsIgnored ( table , _options . Database . Exclude . Tables ) )
6361 {
@@ -74,20 +72,40 @@ public EntityContext Generate(GeneratorOptions options, DatabaseModel databaseMo
7472 GetModels ( entity ) ;
7573 }
7674
75+ foreach ( var view in databaseModel . Views )
76+ {
77+ if ( IsIgnored ( view , _options . Database . Exclude . Tables ) )
78+ {
79+ _logger . LogDebug ( " Skipping View : {schema}.{name}" , view . Schema , view . Name ) ;
80+ continue ;
81+ }
82+
83+ _logger . LogDebug ( " Processing View : {schema}.{name}" , view . Schema , view . Name ) ;
84+
85+ _options . Variables . Set ( VariableConstants . TableSchema , ToLegalName ( view . Schema ) ) ;
86+ _options . Variables . Set ( VariableConstants . TableName , ToLegalName ( view . Name ) ) ;
87+
88+ var entity = GetEntity ( entityContext , view ) ;
89+ GetModels ( entity ) ;
90+ }
91+
7792 _options . Variables . Remove ( VariableConstants . TableName ) ;
7893 _options . Variables . Remove ( VariableConstants . TableSchema ) ;
7994
8095 return entityContext ;
8196 }
8297
8398
84- private Entity GetEntity ( EntityContext entityContext , Table tableSchema , bool processRelationships = true , bool processMethods = true )
99+ private Entity GetEntity ( EntityContext entityContext , RelationBase relationSchema , bool processRelationships = true , bool processMethods = true )
85100 {
86- var entity = entityContext . Entities . ByTable ( tableSchema )
87- ?? CreateEntity ( entityContext , tableSchema ) ;
101+ var entity = entityContext . Entities . ByTable ( relationSchema . Name , relationSchema . Schema )
102+ ?? CreateEntity ( entityContext , relationSchema ) ;
88103
89104 if ( ! entity . Properties . IsProcessed )
90- CreateProperties ( entity , tableSchema ) ;
105+ CreateProperties ( entity , relationSchema ) ;
106+
107+ if ( relationSchema is not Table tableSchema )
108+ return entity ;
91109
92110 if ( processRelationships && ! entity . Relationships . IsProcessed )
93111 CreateRelationships ( entityContext , entity , tableSchema ) ;
@@ -744,9 +762,12 @@ private static string ToLegalName(string? name)
744762 }
745763
746764
747- private static bool IsIgnored ( Table table , IEnumerable < MatchOptions > exclude )
765+ private static bool IsIgnored ( RelationBase ? relation , IEnumerable < MatchOptions > exclude )
748766 {
749- var name = table . QualifiedName ;
767+ if ( relation is null )
768+ return true ;
769+
770+ var name = relation . QualifiedName ;
750771 var includeExpressions = Enumerable . Empty < MatchOptions > ( ) ;
751772 var excludeExpressions = exclude ?? [ ] ;
752773
0 commit comments