Skip to content

Commit 797b269

Browse files
committed
#275 Settings to control context file header comment block
1 parent d4b405d commit 797b269

File tree

3 files changed

+31
-22
lines changed

3 files changed

+31
-22
lines changed

EntityFramework.Reverse.POCO.Generator/Database NorthwindSqlCe40.tt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
UseLazyLoading = true; // Marks all navigation properties as virtual or not, to support or disable EF Lazy Loading feature
3333
IncludeComments = CommentsStyle.AtEndOfField; // Adds comments to the generated code
3434
IncludeExtendedPropertyComments = CommentsStyle.InSummaryBlock; // Adds extended properties as comments to the generated code
35+
IncludeConnectionSettingComments = true; // Add comments describing connection settings used to generate file
3536
IncludeViews = true;
3637
DisableGeographyTypes = false; // Turns off use of System.Data.Entity.Spatial.DbGeography and System.Data.Entity.Spatial.DbGeometry as OData doesn't support entities with geometry/geography types.
3738
CollectionType = "System.Collections.Generic.List"; // Determines the type of collection for the Navigation Properties. "ObservableCollection" for example. Add "System.Collections.ObjectModel" to AdditionalNamespaces if setting the CollectionType = "ObservableCollection".

EntityFramework.Reverse.POCO.Generator/Database.tt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
UseLazyLoading = true; // Marks all navigation properties as virtual or not, to support or disable EF Lazy Loading feature
3333
IncludeComments = CommentsStyle.AtEndOfField; // Adds comments to the generated code
3434
IncludeExtendedPropertyComments = CommentsStyle.InSummaryBlock; // Adds extended properties as comments to the generated code
35+
IncludeConnectionSettingComments = true; // Add comments describing connection settings used to generate file
3536
IncludeViews = true;
3637
IncludeSynonyms = false;
3738
IncludeStoredProcedures = true;

EntityFramework.Reverse.POCO.Generator/EF.Reverse.POCO.Core.ttinclude

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
CommentsStyle IncludeComments = CommentsStyle.AtEndOfField;
6565
bool IncludeQueryTraceOn9481Flag = false;
6666
CommentsStyle IncludeExtendedPropertyComments = CommentsStyle.InSummaryBlock;
67+
bool IncludeConnectionSettingComments = true;
6768
bool AddWcfDataAttributes = false;
6869
string ExtraWcfDataContractAttributes = "";
6970
static bool DisableGeographyTypes = false;
@@ -545,15 +546,18 @@
545546
WriteLine("//");
546547
WriteLine("// Do not make changes directly to this file - edit the template instead.");
547548
WriteLine("//");
548-
WriteLine("// The following connection settings were used to generate this file:");
549-
if (!string.IsNullOrEmpty(ConnectionStringName))
549+
if (IncludeConnectionSettingComments)
550550
{
551-
string solutionPath = Path.GetDirectoryName(GetSolution().FileName) + "\\";
552-
WriteLine("// Configuration file: \"{0}\"", _configFilePath.Replace(solutionPath, String.Empty));
553-
WriteLine("// Connection String Name: \"{0}\"", ConnectionStringName);
551+
WriteLine("// The following connection settings were used to generate this file:");
552+
if (!string.IsNullOrEmpty(ConnectionStringName))
553+
{
554+
string solutionPath = Path.GetDirectoryName(GetSolution().FileName) + "\\";
555+
WriteLine("// Configuration file: \"{0}\"", _configFilePath.Replace(solutionPath, String.Empty));
556+
WriteLine("// Connection String Name: \"{0}\"", ConnectionStringName);
557+
}
558+
WriteLine("// Connection String: \"{0}\"", ZapPassword(ConnectionString));
559+
WriteLine("// ------------------------------------------------------------------------------------------------");
554560
}
555-
WriteLine("// Connection String: \"{0}\"", ZapPassword(ConnectionString));
556-
WriteLine("// ------------------------------------------------------------------------------------------------");
557561

558562
if (!string.IsNullOrEmpty(ProviderName))
559563
{
@@ -624,7 +628,7 @@
624628
PrependSchemaName = false;
625629

626630
var reader = new SqlServerSchemaReader(conn, factory, IncludeQueryTraceOn9481Flag) { Outer = this };
627-
var tables = reader.ReadSchema(SchemaFilterExclude, SchemaFilterInclude, TableFilterExclude, TableFilterInclude, ColumnFilterExclude, TableFilter, UsePascalCase, PrependSchemaName, IncludeComments, IncludeViews, IncludeExtendedPropertyComments, TableRename, UpdateColumn, UsePrivateSetterForComputedColumns, IncludeSynonyms, UseDataAnnotations, UseDataAnnotationsSchema, IsSqlCe, ColumnNameToDataAnnotation);
631+
var tables = reader.ReadSchema(SchemaFilterExclude, SchemaFilterInclude, TableFilterExclude, TableFilterInclude, ColumnFilterExclude, TableFilter, UsePascalCase, PrependSchemaName, IncludeComments, IncludeViews, IncludeExtendedPropertyComments, TableRename, UpdateColumn, UsePrivateSetterForComputedColumns, IncludeSynonyms, UseDataAnnotations, UseDataAnnotationsSchema, IsSqlCe, ColumnNameToDataAnnotation, IncludeConnectionSettingComments);
628632
var fkList = reader.ReadForeignKeys(TableRename, ForeignKeyFilter);
629633
reader.IdentifyForeignKeys(fkList, tables);
630634

@@ -682,7 +686,7 @@
682686
return new List<StoredProcedure>();
683687

684688
var reader = new SqlServerSchemaReader(conn, factory, IncludeQueryTraceOn9481Flag) { Outer = this };
685-
var storedProcs = reader.ReadStoredProcs(SchemaFilterExclude, StoredProcedureFilterExclude, UsePascalCase, PrependSchemaName, StoredProcedureRename, IncludeTableValuedFunctions);
689+
var storedProcs = reader.ReadStoredProcs(SchemaFilterExclude, StoredProcedureFilterExclude, UsePascalCase, PrependSchemaName, StoredProcedureRename, IncludeTableValuedFunctions, IncludeConnectionSettingComments);
686690
conn.Close();
687691

688692
// Remove unrequired stored procs
@@ -1488,13 +1492,13 @@
14881492
}
14891493

14901494
public GeneratedTextTransformation Outer;
1491-
public abstract Tables ReadSchema(Regex schemaFilterExclude, Regex schemaFilterInclude, Regex tableFilterExclude, Regex tableFilterInclude, Regex columnFilterExclude, Func<Table, bool> tableFilter, bool usePascalCase, bool prependSchemaName, CommentsStyle includeComments, bool includeViews, CommentsStyle includeExtendedPropertyComments, Func<string, string, bool, string> tableRename, Func<Column, Table, Column> updateColumn, bool usePrivateSetterForComputedColumns, bool includeSynonyms, bool dataAnnotations, bool dataAnnotationsSchema, bool isSqlCe, Dictionary<string, string> columnNameToDataAnnotation);
1492-
public abstract List<StoredProcedure> ReadStoredProcs(Regex SchemaFilterExclude, Regex storedProcedureFilterExclude, bool usePascalCase, bool prependSchemaName , Func<StoredProcedure, string> StoredProcedureRename, bool includeTableValuedFunctions);
1495+
public abstract Tables ReadSchema(Regex schemaFilterExclude, Regex schemaFilterInclude, Regex tableFilterExclude, Regex tableFilterInclude, Regex columnFilterExclude, Func<Table, bool> tableFilter, bool usePascalCase, bool prependSchemaName, CommentsStyle includeComments, bool includeViews, CommentsStyle includeExtendedPropertyComments, Func<string, string, bool, string> tableRename, Func<Column, Table, Column> updateColumn, bool usePrivateSetterForComputedColumns, bool includeSynonyms, bool dataAnnotations, bool dataAnnotationsSchema, bool isSqlCe, Dictionary<string, string> columnNameToDataAnnotation, bool includeConnectionSettingComments);
1496+
public abstract List<StoredProcedure> ReadStoredProcs(Regex SchemaFilterExclude, Regex storedProcedureFilterExclude, bool usePascalCase, bool prependSchemaName , Func<StoredProcedure, string> StoredProcedureRename, bool includeTableValuedFunctions, bool includeConnectionSettingComments);
14931497
public abstract List<ForeignKey> ReadForeignKeys(Func<string, string, bool, string> tableRename, Func<ForeignKey, ForeignKey> foreignKeyFilter);
14941498
public abstract void ProcessForeignKeys(List<ForeignKey> fkList, Tables tables, bool usePascalCase, bool prependSchemaName, string collectionType, bool checkForFkNameClashes, CommentsStyle includeComments, Func<string, ForeignKey, string, Relationship, short, string> ForeignKeyName, bool dataAnnotationsSchema, Func<IList<ForeignKey>, Table, Table, bool, ForeignKey> foreignKeyProcessing);
14951499
public abstract void IdentifyForeignKeys(List<ForeignKey> fkList, Tables tables);
14961500
public abstract void ReadIndexes(Tables tables);
1497-
public abstract void ReadExtendedProperties(Tables tables);
1501+
public abstract void ReadExtendedProperties(Tables tables, bool includeConnectionSettingComments);
14981502

14991503
protected void WriteLine(string o)
15001504
{
@@ -2101,7 +2105,7 @@ OPTION (QUERYTRACEON 9481)";
21012105
return string.Empty;
21022106
}
21032107

2104-
private bool IsAzure()
2108+
private bool IsAzure(bool includeConnectionSettingComments)
21052109
{
21062110
if (string.IsNullOrEmpty(SqlDatabaseEdition))
21072111
{
@@ -2127,17 +2131,20 @@ SELECT SERVERPROPERTY('Edition') AS Edition,
21272131
{
21282132
SqlDatabaseEdition = rdr["Edition"].ToString();
21292133
SqlDatabaseEngineEdition = rdr["EngineEdition"].ToString();
2130-
WriteLine("// Database Edition : " + SqlDatabaseEdition);
2131-
WriteLine("// Database Engine Edition: " + SqlDatabaseEngineEdition);
2132-
WriteLine("");
2134+
if (includeConnectionSettingComments)
2135+
{
2136+
WriteLine("// Database Edition : " + SqlDatabaseEdition);
2137+
WriteLine("// Database Engine Edition: " + SqlDatabaseEngineEdition);
2138+
WriteLine("");
2139+
}
21332140
}
21342141
}
21352142
}
21362143

21372144
return SqlDatabaseEngineEdition == "Azure";
21382145
}
21392146

2140-
public override Tables ReadSchema(Regex schemaFilterExclude, Regex schemaFilterInclude, Regex tableFilterExclude, Regex tableFilterInclude, Regex columnFilterExclude, Func<Table, bool> tableFilter, bool usePascalCase, bool prependSchemaName, CommentsStyle includeComments, bool includeViews, CommentsStyle includeExtendedPropertyComments, Func<string, string, bool, string> tableRename, Func<Column, Table, Column> updateColumn, bool usePrivateSetterForComputedColumns, bool includeSynonyms, bool dataAnnotations, bool dataAnnotationsSchema, bool isSqlCe, Dictionary<string, string> columnNameToDataAnnotation)
2147+
public override Tables ReadSchema(Regex schemaFilterExclude, Regex schemaFilterInclude, Regex tableFilterExclude, Regex tableFilterInclude, Regex columnFilterExclude, Func<Table, bool> tableFilter, bool usePascalCase, bool prependSchemaName, CommentsStyle includeComments, bool includeViews, CommentsStyle includeExtendedPropertyComments, Func<string, string, bool, string> tableRename, Func<Column, Table, Column> updateColumn, bool usePrivateSetterForComputedColumns, bool includeSynonyms, bool dataAnnotations, bool dataAnnotationsSchema, bool isSqlCe, Dictionary<string, string> columnNameToDataAnnotation, bool includeConnectionSettingComments)
21412148
{
21422149
var result = new Tables();
21432150
if(Cmd == null)
@@ -2232,7 +2239,7 @@ SELECT SERVERPROPERTY('Edition') AS Edition,
22322239
}
22332240

22342241
if (includeExtendedPropertyComments != CommentsStyle.None)
2235-
ReadExtendedProperties(result);
2242+
ReadExtendedProperties(result, includeConnectionSettingComments);
22362243

22372244
ReadIndexes(result);
22382245

@@ -2384,7 +2391,7 @@ SELECT SERVERPROPERTY('Edition') AS Edition,
23842391
}
23852392
}
23862393

2387-
public override void ReadExtendedProperties(Tables tables)
2394+
public override void ReadExtendedProperties(Tables tables, bool includeConnectionSettingComments)
23882395
{
23892396
if(Cmd == null)
23902397
return;
@@ -2400,7 +2407,7 @@ SELECT SERVERPROPERTY('Edition') AS Edition,
24002407
}
24012408
else
24022409
{
2403-
if (IsAzure())
2410+
if (IsAzure(includeConnectionSettingComments))
24042411
return;
24052412

24062413
Cmd.CommandText = ExtendedPropertySQL + IncludeQueryTraceOn9481();
@@ -2436,7 +2443,7 @@ SELECT SERVERPROPERTY('Edition') AS Edition,
24362443
}
24372444
}
24382445

2439-
public override List<StoredProcedure> ReadStoredProcs(Regex schemaFilterExclude, Regex storedProcedureFilterExclude, bool usePascalCase, bool prependSchemaName , Func<StoredProcedure, string> StoredProcedureRename, bool includeTableValuedFunctions)
2446+
public override List<StoredProcedure> ReadStoredProcs(Regex schemaFilterExclude, Regex storedProcedureFilterExclude, bool usePascalCase, bool prependSchemaName , Func<StoredProcedure, string> StoredProcedureRename, bool includeTableValuedFunctions, bool includeConnectionSettingComments)
24402447
{
24412448
var result = new List<StoredProcedure>();
24422449
if(Cmd == null)
@@ -2445,7 +2452,7 @@ SELECT SERVERPROPERTY('Edition') AS Edition,
24452452
if (Cmd.GetType().Name == "SqlCeCommand")
24462453
return result;
24472454

2448-
if (IsAzure())
2455+
if (IsAzure(includeConnectionSettingComments))
24492456
Cmd.CommandText = StoredProcedureSQLAzure + IncludeQueryTraceOn9481();
24502457
else
24512458
Cmd.CommandText = StoredProcedureSQL + IncludeQueryTraceOn9481();

0 commit comments

Comments
 (0)