Skip to content

Commit

Permalink
V5.9.1 has been released.
Browse files Browse the repository at this point in the history
  • Loading branch information
TanvirArjel committed Aug 21, 2022
1 parent de42a31 commit a473631
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 120 deletions.
3 changes: 1 addition & 2 deletions demo/AspNetCore5.0/AspNetCore5.0.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.7" />
<PackageReference Include="Moq" Version="4.18.1" />
<PackageReference Include="TanvirArjel.Extensions.Microsoft.DependencyInjection" Version="2.0.0" />
<PackageReference Include="TanvirArjel.Extensions.Microsoft.DependencyInjection" Version="2.1.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.1;net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>netstandard2.1;net6.0;</TargetFrameworks>
<LangVersion>8.0</LangVersion>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
Expand Down Expand Up @@ -43,9 +43,9 @@
<RepositoryType>Git</RepositoryType>
<PackageTags>EFCore, RepositoryLayer, GenericRepository, UnitOfWork, .NET, .NETCore, ASP.NETCore</PackageTags>
<PackageReleaseNotes>
1. Multiple DbConext support has been added.
1. SQL connection closing isssue has been fixed.
</PackageReleaseNotes>
<Version>6.0.0-preview1</Version>
<Version>5.9.1</Version>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageIcon>icon.png</PackageIcon>
<Authors>TanvirArjel</Authors>
Expand Down Expand Up @@ -73,9 +73,9 @@
<AdditionalFiles Include="stylecop.json" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'">
<!--<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'">
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.0-*" />
</ItemGroup>
</ItemGroup>-->

<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.*" />
Expand Down
111 changes: 0 additions & 111 deletions src/TanvirArjel.EFCore.QueryRepository/SqlQueryExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,12 @@

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data;
using System.Data.Common;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage;

namespace TanvirArjel.EFCore.GenericRepository
{
Expand Down Expand Up @@ -168,111 +163,5 @@ public static async Task<List<T>> GetFromQueryAsync<T>(
await dbContext.Database.CloseConnectionAsync();
}
}

private static async Task<List<T>> GetFromQueryAsync2<T>(
this DbContext dbContext,
string sql,
IEnumerable<object> parameters,
CancellationToken cancellationToken = default)
{
RelationalDataReader relationalDataReader = await dbContext.ExecuteSqlQueryAsync(sql, parameters, cancellationToken);
using DbDataReader dr = relationalDataReader.DbDataReader;

List<T> list = new List<T>();
T t = default;
while (await dr.ReadAsync(cancellationToken))
{
if (!(typeof(T).IsPrimitive || typeof(T).Equals(typeof(string))))
{
PropertyInfo[] props = typeof(T).GetProperties();
IEnumerable<string> actualNames = dr.GetColumnSchema().Select(o => o.ColumnName);
for (int i = 0; i < props.Length; ++i)
{
PropertyInfo pi = props[i];

if (!pi.CanWrite)
{
continue;
}

ColumnAttribute ca = pi.GetCustomAttribute(typeof(ColumnAttribute)) as ColumnAttribute;
string name = ca?.Name ?? pi.Name;

if (pi == null)
{
continue;
}

if (!actualNames.Contains(name))
{
continue;
}

object value = dr[name];
Type pt = pi.DeclaringType;
bool nullable = pt.GetTypeInfo().IsGenericType && pt.GetGenericTypeDefinition() == typeof(Nullable<>);
if (value == DBNull.Value)
{
value = null;
}

if (value == null && pt.GetTypeInfo().IsValueType && !nullable)
{
value = Activator.CreateInstance(pt);
}

pi.SetValue(t, value);
}

list.Add(t);
}
else
{
t = (T)Convert.ChangeType(dr[0], typeof(T), CultureInfo.InvariantCulture);
list.Add(t);
}
}

return list;
}

private static async Task<RelationalDataReader> ExecuteSqlQueryAsync(
this DbContext dbContext,
string sql,
IEnumerable<object> parameters,
CancellationToken cancellationToken = default)
{
if (dbContext == null)
{
throw new ArgumentNullException(nameof(dbContext));
}

if (string.IsNullOrWhiteSpace(sql))
{
throw new ArgumentNullException(nameof(sql));
}

IConcurrencyDetector concurrencyDetector = dbContext.GetService<IConcurrencyDetector>();

using (concurrencyDetector.EnterCriticalSection())
{
RawSqlCommand rawSqlCommand = dbContext
.GetService<IRawSqlCommandBuilder>()
.Build(sql, parameters);

RelationalCommandParameterObject paramObject = new RelationalCommandParameterObject(
dbContext.GetService<IRelationalConnection>(),
rawSqlCommand.ParameterValues,
null,
null,
null);

RelationalDataReader relationalDataReader = await rawSqlCommand
.RelationalCommand
.ExecuteReaderAsync(paramObject, cancellationToken);

return relationalDataReader;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
<RepositoryType>Git</RepositoryType>
<PackageTags>EFCore, RepositoryLayer, GenericRepository, QueryRepository, .NET, .NETCore, ASP.NETCore</PackageTags>
<PackageReleaseNotes>
1. Multiple DbConext support has been added.
1. SQL connection closing isssue has been fixed.
</PackageReleaseNotes>
<Version>1.3.0</Version>
<Version>1.4.0</Version>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<PackageIcon>icon.png</PackageIcon>
<Authors>TanvirArjel</Authors>
Expand Down

0 comments on commit a473631

Please sign in to comment.