Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Commit

Permalink
Merge pull request #23 from PandaTechAM/development
Browse files Browse the repository at this point in the history
Fix ENUM distinct column values for ENUM
  • Loading branch information
ruboarm authored Apr 8, 2024
2 parents 0292f29 + 5a676ca commit d73c518
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/EFCoreQueryMagic/EFCoreQueryMagic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<PackageReadmeFile>Readme.md</PackageReadmeFile>
<Authors>PandaTech</Authors>
<Copyright>MIT</Copyright>
<Version>1.0.2</Version>
<Version>1.0.3</Version>
<PackageId>Pandatech.EFCoreQueryMagic</PackageId>
<Title>Pandatech.EFCoreQueryMagic: Dynamic Query and Filter Generator for EF Core</Title>
<Description>Unlock the full potential of your Entity Framework Core applications with Pandatech.EFCoreQueryMagic. This innovative package empowers developers to seamlessly create dynamic, complex queries and filters for SQL tables without diving deep into the intricacies of LINQ or manual query construction. Designed to enhance productivity and maintainability, EFCoreQueryMagic automates the translation of front-end filter requests into optimized, ready-to-execute EF Core queries. Embrace the magic of streamlined data retrieval and manipulation, and elevate your applications to new heights of efficiency and performance.</Description>
Expand Down
44 changes: 36 additions & 8 deletions src/EFCoreQueryMagic/Extensions/DistinctColumnValuesExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,34 @@ public static DistinctColumnValues DistinctColumnValues<TModel>(this IQueryable<

var query3 = query2.Distinct();

IQueryable<object> paged;
List<object> queried;

if (propertyType.EnumCheck())
{
var excludedValues = Enum.GetValues(GetEnumerableType(propertyType)).Cast<object>()
.Where(x => (x as Enum)!.HasAttributeOfType<HideEnumValueAttribute>())
.ToList();

if (excludedValues.Count != 0)
query3 = query3.Where(x => !excludedValues.Contains(x));
{
queried = query3.ToList().Where(x => !excludedValues.Contains(x)).Skip(pageSize * (page - 1))
.Take(pageSize).ToList();
}
else
{
queried = query3.ToList().Skip(pageSize * (page - 1))
.Take(pageSize).ToList();
}
}
else
{
paged = query3.Skip(pageSize * (page - 1)).Take(pageSize);
queried = paged.ToList();
}

var paged = query3.Skip(pageSize * (page - 1)).Take(pageSize);
var queried = paged.ToList();
var converted = queried.Select(x => method.Invoke(converter, [x])!);

result.Values = converted
.Distinct().OrderBy(x => x).ToList();

Expand Down Expand Up @@ -164,20 +178,34 @@ public static async Task<DistinctColumnValues> DistinctColumnValuesAsync<TModel>

var query3 = query2.Distinct();

IQueryable<object> paged;
List<object> queried;

if (propertyType.EnumCheck())
{
var excludedValues = Enum.GetValues(GetEnumerableType(propertyType)).Cast<object>()
.Where(x => (x as Enum)!.HasAttributeOfType<HideEnumValueAttribute>())
.ToList();

if (excludedValues.Count != 0)
query3 = query3.Where(x => !excludedValues.Contains(x));
{
queried = query3.ToList().Where(x => !excludedValues.Contains(x)).Skip(pageSize * (page - 1))
.Take(pageSize).ToList();
}
else
{
queried = query3.ToList().Skip(pageSize * (page - 1))
.Take(pageSize).ToList();
}
}
else
{
paged = query3.Skip(pageSize * (page - 1)).Take(pageSize);
queried = await paged.ToListAsync(cancellationToken: cancellationToken);
}

var paged = query3.Skip(pageSize * (page - 1)).Take(pageSize);
var queried = await paged.ToListAsync(cancellationToken: cancellationToken);
var converted = queried.Select(x => method.Invoke(converter, [x])!);

result.Values = converted
.Distinct().OrderBy(x => x).ToList();

Expand Down
5 changes: 4 additions & 1 deletion test/EFCoreQueryMagic.Test/Enums/PaymentStatus.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
namespace EFCoreQueryMagic.Test.Enums;
using EFCoreQueryMagic.Attributes;

namespace EFCoreQueryMagic.Test.Enums;

public enum PaymentStatus
{
Pending,
Completed,
[HideEnumValue]
Failed
}

0 comments on commit d73c518

Please sign in to comment.