1
+ using QuantumConcepts . CodeGenerator . Core . Utils ;
2
+ using QuantumConcepts . Common . Extensions ;
1
3
using System ;
2
4
using System . Collections . Generic ;
3
- using System . Text ;
4
- using System . Xml . Serialization ;
5
- using QuantumConcepts . CodeGenerator . Core . Utils ;
6
5
using System . IO ;
7
- using System . Xml ;
8
- using System . Xml . XPath ;
9
6
using System . Linq ;
10
- using QuantumConcepts . Common . Extensions ;
7
+ using System . Xml ;
11
8
using System . Xml . Linq ;
12
- using QuantumConcepts . Common . Utils ;
13
- using QuantumConcepts . CodeGenerator . Core . Upgrade ;
9
+ using System . Xml . Serialization ;
14
10
15
11
namespace QuantumConcepts . CodeGenerator . Core . ProjectSchema
16
12
{
@@ -122,6 +118,8 @@ public XDocument GetXDocument(out XmlNamespaceManager nsm)
122
118
123
119
private void Initialize ( )
124
120
{
121
+ EnsureConnectionsExist ( ) ;
122
+
125
123
this . UserSettings . JoinToProject ( this ) ;
126
124
this . Connections . ForEach ( o => o . JoinToParent ( this ) ) ;
127
125
this . DataTypeMappings . ForEach ( o => o . JoinToProject ( this ) ) ;
@@ -131,6 +129,25 @@ private void Initialize()
131
129
this . ForeignKeyMappings . ForEach ( o => o . JoinToProject ( this ) ) ;
132
130
}
133
131
132
+ private void EnsureConnectionsExist ( )
133
+ {
134
+ var connectionNames = this . Connections . Select ( o => o . Name ) . Union ( this . UserSettings . Connections . Select ( o => o . Name ) ) . Distinct ( ) . ToList ( ) ;
135
+
136
+ this . Connections . AddRange ( ( from name in connectionNames
137
+ where ! this . Connections . Any ( o => string . Equals ( o . Name , name ) )
138
+ select new ConnectionInfo
139
+ {
140
+ Name = name
141
+ } ) ) ;
142
+
143
+ this . UserSettings . Connections . AddRange ( ( from name in connectionNames
144
+ where ! this . UserSettings . Connections . Any ( o => string . Equals ( o . Name , name ) )
145
+ select new Connection
146
+ {
147
+ Name = name
148
+ } ) ) ;
149
+ }
150
+
134
151
public DataTypeMapping FindDataTypeMapping ( string databaseDataType )
135
152
{
136
153
return this . DataTypeMappings . SingleOrDefault ( o => o . DatabaseDataType . EqualsIgnoreCase ( databaseDataType ) ) ;
@@ -140,7 +157,7 @@ public TableMapping FindTableMapping(string connectionName, string schemaName, s
140
157
{
141
158
return this . TableMappings . SingleOrDefault ( o =>
142
159
o . ConnectionName . EqualsIgnoreCase ( connectionName )
143
- && o . SchemaName . EqualsIgnoreCase ( schemaName )
160
+ && o . SchemaName . EqualsIgnoreCase ( schemaName )
144
161
&& o . TableName . EqualsIgnoreCase ( name ) ) ;
145
162
}
146
163
@@ -151,9 +168,9 @@ public Template FindTemplate(string xsltAbsolutePath)
151
168
152
169
public ViewMapping FindViewMapping ( string connectionName , string schemaName , string name )
153
170
{
154
- return this . ViewMappings . SingleOrDefault ( o =>
171
+ return this . ViewMappings . SingleOrDefault ( o =>
155
172
o . ConnectionName . EqualsIgnoreCase ( connectionName )
156
- && o . SchemaName . EqualsIgnoreCase ( schemaName )
173
+ && o . SchemaName . EqualsIgnoreCase ( schemaName )
157
174
&& o . TableName . EqualsIgnoreCase ( name ) ) ;
158
175
}
159
176
0 commit comments