Skip to content

Commit ec7397b

Browse files
committed
Tsql deserialization fixed
1 parent f49e542 commit ec7397b

File tree

5 files changed

+54
-42
lines changed

5 files changed

+54
-42
lines changed

Tsql/Configuration/TsqlConfigurationReader.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public virtual ConfigurationBase Read(XElement rootElement, XElement configurati
3131
.MapList("Entity", "Entities")
3232
//.Map<TsqlDataContext>("DataContext")
3333
//.MapList("DataContext", "Entities")
34-
.Map("StoredProcedure",element => new TsqlStoredProcedure(element.Value))
35-
.MapList("StoredProcedure", "StoredProcedures")
34+
.Map("/Tsql/Entity/DataContext/StoredProcedure", element => new TsqlStoredProcedure(element.Value))
35+
.MapList("/Tsql/Entity/DataContext/StoredProcedure", "StoredProcedures")
3636
.Map(this.ReadControllerMethod)
3737
.Deserialize(configurationElement, configuration);
3838

@@ -103,11 +103,11 @@ private void Validate(TsqlConfiguration configuration)
103103
{
104104
if (string.IsNullOrEmpty(entity.Schema))
105105
{
106-
throw new InvalidConfigurationException($"Tsql entity {nameof(entity.Schema)} can not be null or empty");
106+
throw new InvalidConfigurationException($"Tsql entity '{entity.Name ?? "without name"}' {nameof(entity.Schema)} can not be null or empty");
107107
}
108108
if (string.IsNullOrEmpty(entity.Table) && string.IsNullOrEmpty(entity.StoredProcedure))
109109
{
110-
throw new InvalidConfigurationException($"Tsql entity {nameof(entity.Table)} can not be null or empty");
110+
throw new InvalidConfigurationException($"Tsql entity '{entity.Name ?? "without name"}' {nameof(entity.Table)} can not be null or empty");
111111
}
112112
}
113113
}

Tsql/KY.Generator.Tsql.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<copyright>Copyright 2018</copyright>
1616
<tags>KY Generator TSQL EntityFramework Entity Framework EF</tags>
1717
<dependencies>
18-
<dependency id="KY.Core.Common" version="3.5.1480" />
18+
<dependency id="KY.Core.Common" version="3.5.1484" />
1919
<dependency id="KY.Generator.Core" version="0.7.1480" />
2020
<dependency id="KY.Generator.Csharp" version="0.7.1480" />
2121
<dependency id="KY.Generator.TypeScript" version="0.7.1480" />

Tsql/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@
3030
// You can specify all the values or you can default the Build and Revision Numbers
3131
// by using the '*' as shown below:
3232
// [assembly: AssemblyVersion("1.0.*")]
33-
[assembly: AssemblyVersion("0.7.1481")]
33+
[assembly: AssemblyVersion("0.7.1484")]
3434
[assembly: AssemblyFileVersion("0.7.0.0")]

Tsql/Type/TsqlTypeReader.cs

Lines changed: 47 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -117,21 +117,25 @@ public List<List<string>> GetValues(string schema, string table, params string[]
117117
{
118118
List<List<string>> rows = new List<List<string>>();
119119
this.OpenConnection();
120-
SqlCommand command = this.connection.CreateCommand();
121-
command.CommandText = string.Format(Resources.ReadValuesCommand, string.Join(", ", columns), schema, table);
122-
command.Parameters.AddWithValue("schema", schema);
123-
command.Parameters.AddWithValue("name", table);
124-
SqlDataReader reader = command.ExecuteReader();
125-
if (reader.HasRows)
120+
using (SqlCommand command = this.connection.CreateCommand())
126121
{
127-
while (reader.Read())
122+
command.CommandText = string.Format(Resources.ReadValuesCommand, string.Join(", ", columns), schema, table);
123+
command.Parameters.AddWithValue("schema", schema);
124+
command.Parameters.AddWithValue("name", table);
125+
using (SqlDataReader reader = command.ExecuteReader())
128126
{
129-
List<string> row = new List<string>();
130-
for (int ordinal = 0; ordinal < columns.Length; ordinal++)
127+
if (reader.HasRows)
131128
{
132-
row.Add(reader.GetValue(ordinal).ToString());
129+
while (reader.Read())
130+
{
131+
List<string> row = new List<string>();
132+
for (int ordinal = 0; ordinal < columns.Length; ordinal++)
133+
{
134+
row.Add(reader.GetValue(ordinal).ToString());
135+
}
136+
rows.Add(row);
137+
}
133138
}
134-
rows.Add(row);
135139
}
136140
}
137141
return rows;
@@ -144,22 +148,24 @@ public List<TsqlParameter> GetParameters(string schema, string storedProcedure)
144148
try
145149
{
146150
this.OpenConnection();
147-
SqlCommand command = this.connection.CreateCommand();
148-
command.CommandText = Resources.ReadParametersCommand;
149-
command.Parameters.AddWithValue("schema", schema);
150-
command.Parameters.AddWithValue("name", storedProcedure);
151-
using (SqlDataReader reader = command.ExecuteReader())
151+
using (SqlCommand command = this.connection.CreateCommand())
152152
{
153-
if (reader.HasRows)
153+
command.CommandText = Resources.ReadParametersCommand;
154+
command.Parameters.AddWithValue("schema", schema);
155+
command.Parameters.AddWithValue("name", storedProcedure);
156+
using (SqlDataReader reader = command.ExecuteReader())
154157
{
155-
while (reader.Read())
158+
if (reader.HasRows)
156159
{
157-
TsqlParameter parameter = new TsqlParameter();
158-
parameter.Name = reader.GetString(reader.GetOrdinal("PARAMETER_NAME"));
159-
parameter.Type = reader.GetString(reader.GetOrdinal("DATA_TYPE"));
160-
parameter.Order = reader.GetInt32(reader.GetOrdinal("ORDINAL_POSITION"));
161-
parameter.IsNullable = true;
162-
list.Add(parameter);
160+
while (reader.Read())
161+
{
162+
TsqlParameter parameter = new TsqlParameter();
163+
parameter.Name = reader.GetString(reader.GetOrdinal("PARAMETER_NAME"));
164+
parameter.Type = reader.GetString(reader.GetOrdinal("DATA_TYPE"));
165+
parameter.Order = reader.GetInt32(reader.GetOrdinal("ORDINAL_POSITION"));
166+
parameter.IsNullable = true;
167+
list.Add(parameter);
168+
}
163169
}
164170
}
165171
}
@@ -182,27 +188,33 @@ public List<TsqlColumn> GetColumnsFromStoredProcedure(string schema, string stor
182188
this.LastError = null;
183189
string key = $"{schema}.{storedProcedure}";
184190
if (this.columnsCache.ContainsKey(key))
191+
{
185192
return this.columnsCache[key];
193+
}
186194

187195
List<TsqlColumn> columns = new List<TsqlColumn>();
188196
try
189197
{
190198
this.OpenConnection();
191-
SqlCommand command = this.connection.CreateCommand();
192-
command.CommandText = string.Format(Resources.ReadResultCommand, key);
193-
SqlDataReader reader = command.ExecuteReader();
194-
if (reader.HasRows)
199+
using (SqlCommand command = this.connection.CreateCommand())
195200
{
196-
while (reader.Read())
201+
command.CommandText = string.Format(Resources.ReadResultCommand, key);
202+
using (SqlDataReader reader = command.ExecuteReader())
197203
{
198-
columns.Add(this.ReadColumn(reader));
204+
if (reader.HasRows)
205+
{
206+
while (reader.Read())
207+
{
208+
columns.Add(this.ReadColumn(reader));
209+
}
210+
}
211+
this.columnsCache.Add(key, columns);
212+
if (columns.All(x => !x.IsPrimaryKey))
213+
{
214+
columns.ForEach(x => x.IsPrimaryKey = !x.IsNullable);
215+
}
199216
}
200217
}
201-
this.columnsCache.Add(key, columns);
202-
if (columns.All(x => !x.IsPrimaryKey))
203-
{
204-
columns.ForEach(x => x.IsPrimaryKey = !x.IsNullable);
205-
}
206218
}
207219
catch (SqlException exception)
208220
{

Tsql/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="KY.Core.Common" version="3.5.1480" targetFramework="net452" />
3+
<package id="KY.Core.Common" version="3.5.1482" targetFramework="net452" />
44
<package id="KY.Core.Meta" version="3.5.1480" targetFramework="net452" />
55
</packages>

0 commit comments

Comments
 (0)