Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail to GroupBy Select Where Average #633

Closed
Cricle opened this issue Oct 15, 2022 · 3 comments
Closed

Fail to GroupBy Select Where Average #633

Cricle opened this issue Oct 15, 2022 · 3 comments
Assignees
Labels

Comments

@Cricle
Copy link

Cricle commented Oct 15, 2022

1. Description

Describe the issue or propose a feature.

2. Exception

public class DataSetA
{
    public string Name { get; set; }

    public int Id { get; set; }

    public DateTime Time { get; set; }

    public int? L { get; set; }
}

var ds = new DataSetA[0];
var q = ds.AsQueryable()
    .GroupBy("Time")
    .Select("new (Select(L).Where(it!=null).Average() as q)");//Error

var q1 = ds.GroupBy(x => x.Time)
    .Select(x => new { q = x.Select(d => d.L).Where(d => d != null).Average() });//Ok
   在 System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseEnumerable(Expression instance, Type elementType, String methodName, Int32 errorPos, Type type)
   在 System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseMemberAccess(Type type, Expression expression)
   在 System.Linq.Dynamic.Core.Parser.ExpressionParser.ParsePrimary()
   在 System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseUnary()
   在 System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseMultiplicative()
   在 System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseAdditive()
   在 System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseShiftOperator()
   在 System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseComparisonOperator()
   在 System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseLogicalAndOrOperator()
   在 System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseIn()
   在 System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseAndOperator()
   在 System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseOrOperator()
   在 System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseLambdaOperator()
   在 System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseNullCoalescingOperator()
   在 System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseConditionalOperator()
   在 System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseNew()
   在 System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseIdentifier()
   在 System.Linq.Dynamic.Core.Parser.ExpressionParser.ParsePrimary()
   在 System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseUnary()
   在 System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseMultiplicative()
   在 System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseAdditive()
   在 System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseShiftOperator()
   在 System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseComparisonOperator()
   在 System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseLogicalAndOrOperator()
   在 System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseIn()
   在 System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseAndOperator()
   在 System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseOrOperator()
   在 System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseLambdaOperator()
   在 System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseNullCoalescingOperator()
   在 System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseConditionalOperator()
   在 System.Linq.Dynamic.Core.Parser.ExpressionParser.Parse(Type resultType, Boolean createParameterCtor)
   在 System.Linq.Dynamic.Core.DynamicExpressionParser.ParseLambda(Type delegateType, ParsingConfig parsingConfig, Boolean createParameterCtor, ParameterExpression[] parameters, Type resultType, String expression, Object[] values)
   在 System.Linq.Dynamic.Core.DynamicQueryableExtensions.Select(IQueryable source, ParsingConfig config, String selector, Object[] args)

3. Fiddle or Project

4. Any further technical details

@Cricle Cricle changed the title Fail to Select->Where->Average Fail to GroupBy->Select->Where->Average Oct 15, 2022
@Cricle
Copy link
Author

Cricle commented Oct 15, 2022

var q = ds.AsQueryable()
                .GroupBy("Time")
                .Select("new (Where(L!=null).Any()? (Sum(L)/Where(L!=null).Count()):null as q)")
                .ToDynamicList();//OK

var q1 = ds.GroupBy(x => x.Time)
    .Select(x => new { q = x.Select(d => d.L).Where(d => d != null).Average() })
    .ToDynamicList();//OK

I must use that replace origin.

@StefH
Copy link
Collaborator

StefH commented Nov 26, 2022

@Cricle
Is this still an issue, or did you solve it yourself?

@Cricle
Copy link
Author

Cricle commented Nov 30, 2022

It still an issue.

@StefH StefH self-assigned this May 1, 2024
@StefH StefH added the bug label May 1, 2024
@StefH StefH closed this as completed May 1, 2024
@StefH StefH changed the title Fail to GroupBy->Select->Where->Average Fail to GroupBy Select Where Average May 3, 2024
@StefH StefH changed the title Fail to GroupBy Select Where Average Fail to GroupBy Select Where Average May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants