diff --git a/GridBlazor/GridBlazor.csproj b/GridBlazor/GridBlazor.csproj
index 4da31ce8..0bc45152 100644
--- a/GridBlazor/GridBlazor.csproj
+++ b/GridBlazor/GridBlazor.csproj
@@ -6,7 +6,7 @@
11.0
True
False
- 5.0.8
+ 5.0.9
GridBlazor
Grid components for Blazor
Grid components for Blazor
diff --git a/GridCore/GridCore.csproj b/GridCore/GridCore.csproj
index 7a51bb0b..932bded5 100644
--- a/GridCore/GridCore.csproj
+++ b/GridCore/GridCore.csproj
@@ -7,7 +7,7 @@
False
GridCore
GridCore
- 7.0.5
+ 7.0.6
GridCore
Grid core component
Grid core component
diff --git a/GridMvc/GridMvc.csproj b/GridMvc/GridMvc.csproj
index 255256b1..4733520f 100644
--- a/GridMvc/GridMvc.csproj
+++ b/GridMvc/GridMvc.csproj
@@ -8,7 +8,7 @@
False
GridMvc
GridMvcCore
- 7.0.5
+ 7.0.6
GridMvc
ASP.NET MVC Grid component
ASP.NET MVC Grid component
diff --git a/GridShared/Filtering/Types/FilterTypeBase.cs b/GridShared/Filtering/Types/FilterTypeBase.cs
index 3166bfde..c541b10e 100644
--- a/GridShared/Filtering/Types/FilterTypeBase.cs
+++ b/GridShared/Filtering/Types/FilterTypeBase.cs
@@ -82,18 +82,17 @@ protected Expression GetFilterExpression(Expression leftExpr, string value
case GridFilterType.GreaterThanOrEquals:
return Expression.GreaterThanOrEqual(leftExpr, valueExpr);
case GridFilterType.IsDuplicated:
- Expression groupBy = GetGroupBy(source, leftExpr);
+ Expression groupBy = GetDuplicatedGroupBy(source, leftExpr);
MethodInfo methodInfo = typeof(Queryable).GetMethods()
.Single(r => r.Name == "Contains" && r.GetParameters().Length == 2)
.MakeGenericMethod(new Type[] { typeof(S) });
return Expression.Call(methodInfo, groupBy, leftExpr);
case GridFilterType.IsNotDuplicated:
- groupBy = GetGroupBy(source, leftExpr);
+ groupBy = GetNotDuplicatedGroupBy(source, leftExpr);
methodInfo = typeof(Queryable).GetMethods()
.Single(r => r.Name == "Contains" && r.GetParameters().Length == 2)
.MakeGenericMethod(new Type[] { typeof(S) });
- var expresion = Expression.Call(methodInfo, groupBy, leftExpr);
- return Expression.Not(expresion);
+ return Expression.Call(methodInfo, groupBy, leftExpr);
default:
throw new ArgumentOutOfRangeException();
}
@@ -101,7 +100,7 @@ protected Expression GetFilterExpression(Expression leftExpr, string value
#endregion
- protected Expression GetGroupBy(Expression source, Expression expression)
+ protected Expression GetDuplicatedGroupBy(Expression source, Expression expression)
{
if (expression == null)
return null;
@@ -146,6 +145,51 @@ protected Expression GetGroupBy(Expression source, Expression expression)
return binaryExpression;
}
+ protected Expression GetNotDuplicatedGroupBy(Expression source, Expression expression)
+ {
+ if (expression == null)
+ return null;
+
+ List names = new List();
+ while (expression.NodeType != ExpressionType.Parameter)
+ {
+ names.Add(((MemberExpression)expression).Member.Name);
+ expression = ((MemberExpression)expression).Expression;
+ }
+
+ Type entityType = typeof(T);
+ ParameterExpression parameter = Expression.Parameter(entityType, "c");
+
+ Expression binaryExpression = parameter;
+ for (int i = names.Count - 1; i >= 0; i--)
+ {
+ binaryExpression = Expression.Property(binaryExpression, names[i]);
+ }
+
+ var selector = Expression.Lambda>(binaryExpression, parameter);
+
+ var methodInfo = typeof(Queryable).GetMethods()
+ .Single(r => r.Name == "GroupBy" && r.GetParameters().Length == 2)
+ .MakeGenericMethod(new Type[] { typeof(T), typeof(S) });
+ binaryExpression = Expression.Call(methodInfo, source, selector);
+
+ methodInfo = typeof(Queryable).GetMethods()
+ .Where(r => r.Name == "Where" && r.GetParameters().Length == 2)
+ .First()
+ .MakeGenericMethod(new Type[] { typeof(IGrouping) }); ;
+ Expression, bool>> having = c => c.Count() <= 1;
+ binaryExpression = Expression.Call(methodInfo, binaryExpression, having);
+
+ methodInfo = typeof(Queryable).GetMethods()
+ .Where(r => r.Name == "Select" && r.GetParameters().Length == 2)
+ .First()
+ .MakeGenericMethod(new Type[] { typeof(IGrouping), typeof(S) });
+ Expression, S>> select = c => c.Key;
+ binaryExpression = Expression.Call(methodInfo, binaryExpression, select);
+
+ return binaryExpression;
+ }
+
#region OData
public virtual string GetFilterExpression(string columnName, string value, GridFilterType filterType)
diff --git a/GridShared/Filtering/Types/GuidFilterType.cs b/GridShared/Filtering/Types/GuidFilterType.cs
index ab6649c6..e95ff70b 100644
--- a/GridShared/Filtering/Types/GuidFilterType.cs
+++ b/GridShared/Filtering/Types/GuidFilterType.cs
@@ -73,19 +73,18 @@ public override Expression GetFilterExpression(Expression leftExpr, string va
binaryExpression = GetCaseInsensitiveСomparation("EndsWith", toStringLeftExpr, valueExpr);
break;
case GridFilterType.IsDuplicated:
- Expression groupBy = GetGroupBy(source, leftExpr);
+ Expression groupBy = GetDuplicatedGroupBy(source, leftExpr);
MethodInfo methodInfo = typeof(Queryable).GetMethods()
.Single(r => r.Name == "Contains" && r.GetParameters().Length == 2)
.MakeGenericMethod(new Type[] { typeof(Guid) });
binaryExpression = Expression.Call(methodInfo, groupBy, toStringLeftExpr);
break;
case GridFilterType.IsNotDuplicated:
- groupBy = GetGroupBy(source, leftExpr);
+ groupBy = GetNotDuplicatedGroupBy(source, leftExpr);
methodInfo = typeof(Queryable).GetMethods()
.Single(r => r.Name == "Contains" && r.GetParameters().Length == 2)
.MakeGenericMethod(new Type[] { typeof(Guid) });
- var expresion = Expression.Call(methodInfo, groupBy, toStringLeftExpr);
- binaryExpression = Expression.Not(expresion);
+ binaryExpression = Expression.Call(methodInfo, groupBy, toStringLeftExpr);
break;
default:
throw new ArgumentOutOfRangeException();
diff --git a/GridShared/Filtering/Types/TextFilterType.cs b/GridShared/Filtering/Types/TextFilterType.cs
index cff32a1d..6e05ce06 100644
--- a/GridShared/Filtering/Types/TextFilterType.cs
+++ b/GridShared/Filtering/Types/TextFilterType.cs
@@ -73,19 +73,18 @@ public override Expression GetFilterExpression(Expression leftExpr, string va
binaryExpression = GetCaseInsensitiveСomparation("EndsWith", leftExpr, valueExpr, removeDiacritics);
break;
case GridFilterType.IsDuplicated:
- Expression groupBy = GetGroupBy(source, leftExpr);
+ Expression groupBy = GetDuplicatedGroupBy(source, leftExpr);
MethodInfo methodInfo = typeof(Queryable).GetMethods()
.Single(r => r.Name == "Contains" && r.GetParameters().Length == 2)
.MakeGenericMethod(new Type[] { typeof(string) });
binaryExpression = Expression.Call(methodInfo, groupBy, leftExpr);
break;
case GridFilterType.IsNotDuplicated:
- groupBy = GetGroupBy(source, leftExpr);
+ groupBy = GetNotDuplicatedGroupBy(source, leftExpr);
methodInfo = typeof(Queryable).GetMethods()
.Single(r => r.Name == "Contains" && r.GetParameters().Length == 2)
.MakeGenericMethod(new Type[] { typeof(string) });
- var expresion = Expression.Call(methodInfo, groupBy, leftExpr);
- binaryExpression = Expression.Not(expresion);
+ binaryExpression = Expression.Call(methodInfo, groupBy, leftExpr);
break;
default:
throw new ArgumentOutOfRangeException();
diff --git a/GridShared/GridShared.csproj b/GridShared/GridShared.csproj
index 03ae107a..602c7217 100644
--- a/GridShared/GridShared.csproj
+++ b/GridShared/GridShared.csproj
@@ -3,7 +3,7 @@
netstandard2.1;net5.0;net6.0;net7.0;net8.0
11.0
- 7.0.4
+ 7.0.5
GridShared
Support library for GridBlazor and GridMvcCore component libraries
Support library for GridBlazor and GridMvcCore component libraries