Skip to content

Commit

Permalink
Performance improved
Browse files Browse the repository at this point in the history
  • Loading branch information
sheryever committed May 8, 2020
1 parent 3e49463 commit c219549
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
6 changes: 3 additions & 3 deletions Source/SimpleAccess.SqlServer/SimpleAccess.SqlServer.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="Current">
<PropertyGroup>
<TargetFrameworks>net40;net45;netstandard2.0;netstandard2.1</TargetFrameworks>
<Version>3.1.0-rc-4</Version>
<Version>3.1.0-rc-5</Version>
<Product>SimpleAccess Sql Server ORM</Product>
<Description>Simple Access ORM provides database access in Ado.net methods naming pattern.
Documentation of using SimpleAccess is available at https://simpleaccessorm.com
Expand Down Expand Up @@ -34,8 +34,8 @@ Documentation of using SimpleAccess is available at https://simpleaccessorm.com
Bug fixes
- SqlEntityRepository Get, Find, FindAll methods fixed
- Insert is not working with Indentity column</PackageReleaseNotes>
<AssemblyVersion>3.1.0.9</AssemblyVersion>
<FileVersion>3.1.0.9</FileVersion>
<AssemblyVersion>3.1.0.10</AssemblyVersion>
<FileVersion>3.1.0.10</FileVersion>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.0'">
Expand Down
17 changes: 9 additions & 8 deletions Source/SimpleAccess.SqlServer/SqlSimpleAccess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ public TEntity ExecuteEntity<TEntity>(string commandText, CommandType commandTyp
{
dbCommand = CreateCommand(commandText, commandType, sqlParameters);
dbCommand.Connection.OpenSafely();
using (var reader = dbCommand.ExecuteReader(CommandBehavior.SingleRow))
using (var reader = dbCommand.ExecuteReader(CommandBehavior.SingleResult | CommandBehavior.SingleRow ))
{
return reader.HasRows ? reader.DataReaderToObject<TEntity>(fieldsToSkip, propertyInfoDictionary) : null;
}
Expand Down Expand Up @@ -1104,7 +1104,7 @@ public TEntity ExecuteEntity<TEntity>(SqlTransaction sqlTransaction, string comm
{
dbCommand = CreateCommand(sqlTransaction, commandText, commandType, sqlParameters);
dbCommand.Connection.OpenSafely();
using (var reader = dbCommand.ExecuteReader())
using (var reader = dbCommand.ExecuteReader(CommandBehavior.SingleResult | CommandBehavior.SingleRow))
{
return reader.HasRows ? reader.DataReaderToObject<TEntity>(fieldsToSkip, propertyInfoDictionary) : null;
}
Expand Down Expand Up @@ -1371,7 +1371,7 @@ public dynamic ExecuteDynamic(string commandText, CommandType commandType, strin
{
dbCommand = CreateCommand(commandText, commandType, sqlParameters);
dbCommand.Connection.OpenSafely();
var reader = dbCommand.ExecuteReader(CommandBehavior.SingleRow);
var reader = dbCommand.ExecuteReader(CommandBehavior.SingleResult | CommandBehavior.SingleRow);
if (reader.Read())
{
var result = SqlDataReaderToExpando(reader);
Expand Down Expand Up @@ -1463,7 +1463,7 @@ public dynamic ExecuteDynamic(SqlTransaction sqlTransaction, string commandText,
{
dbCommand = CreateCommand(sqlTransaction, commandText, commandType, sqlParameters);
dbCommand.Connection.OpenSafely();
using (var reader = dbCommand.ExecuteReader())
using (var reader = dbCommand.ExecuteReader(CommandBehavior.SingleResult | CommandBehavior.SingleRow))
{
if (reader.Read())
return SqlDataReaderToExpando(reader);
Expand Down Expand Up @@ -1643,14 +1643,14 @@ public SqlTransaction BeginTransaction(IsolationLevel isolationLevel, string tra
/// <returns> The new command. </returns>
public SqlCommand CreateCommand(string commandText, CommandType commandType, params SqlParameter[] sqlParameters)
{
var dbCommand = _sqlConnection.CreateCommand();
var dbCommand = new SqlCommand(commandText, _sqlConnection);
//_sqlConnection.CreateCommand();
dbCommand.CommandTimeout = DefaultSimpleAccessSettings.DbCommandTimeout;
dbCommand.CommandType = commandType;
dbCommand.CommandText = commandText;
//dbCommand.CommandText = commandText;
if (sqlParameters != null)
dbCommand.Parameters.AddRange(sqlParameters);


return dbCommand;
}

Expand Down Expand Up @@ -1713,7 +1713,8 @@ public dynamic SqlDataReaderToExpando(SqlDataReader reader)
for (var i = 0; i < reader.FieldCount; i++)
{
var value = reader[i];
expandoObject.Add(reader.GetName(i), value == DBNull.Value ? null : value);
if (value != null)
expandoObject.Add(reader.GetName(i), value);
}

return expandoObject;
Expand Down

0 comments on commit c219549

Please sign in to comment.