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

Unrecognize the Generic Type when parse the lambda expression string #742

Open
zobinlee opened this issue Sep 8, 2023 · 2 comments
Open
Assignees
Labels

Comments

@zobinlee
Copy link

zobinlee commented Sep 8, 2023

1. Description

I got an error when parse below lambda expression string

SqlFunc.Subqueryable<QMS.Base.Entities.Catalog>()
.Where(s1=>s0.CatalogId=s1.Id && ( s1.HandlerUserId=1  || !(s1.TypeValue ="provider" && s1.ParentId =  0 )))
.Any()

I have set the config like

 var parsingCfg = new ParsingConfig()
{
  CustomTypeProvider = new SqlSugarTypeProvider()
};

public class SqlSugarTypeProvider : DefaultDynamicLinqCustomTypeProvider
    { 
        public override HashSet<Type> GetCustomTypes()
        {
            var customTypes = base.GetCustomTypes();
            customTypes.Add(typeof(SqlFunc));
            customTypes.Add(typeof(Subqueryable<>)); 

            return customTypes;
        }
    }

and the SqlFunc define:

public class SqlFunc
{
  ....
   public static Subqueryable<T> Subqueryable<T>() where T:class,new(){ throw new NotSupportedException("Can only be used in expressions");} 
  ....
}

2. Exception

System.Linq.Dynamic.Core.Exceptions.ParseException:“No property or field 'Subqueryable' exists in type 'SqlFunc'”
Exception message:
Stack trace:
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseMemberAccess(Type type, Expression expression)
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseTypeAccess(Type type, Boolean getNext)
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseIdentifier()
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParsePrimary()
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseUnary()
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseMultiplicative()
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseAdditive()
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseShiftOperator()
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseComparisonOperator()
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseLogicalAndOrOperator()
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseIn()
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseAndOperator()
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseOrOperator()
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseLambdaOperator()
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseNullCoalescingOperator()
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseConditionalOperator()
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.Parse(Type resultType, Boolean createParameterCtor)
   at System.Linq.Dynamic.Core.DynamicExpressionParser.ParseLambda(Type delegateType, ParsingConfig parsingConfig, Boolean createParameterCtor, ParameterExpression[] parameters, Type resultType, String expression, Object[] values)
   at  System.Linq.Dynamic.Core.DynamicExpressionParser.ParseLambda(ParsingConfig parsingConfig, ParameterExpression[] parameters, Type resultType, String expression, Object[] values)
   at QMS.Application.Services.Repository`1.<>c__DisplayClass12_1.<.cctor>b__11(IGrouping`2 g) at  QMS.Application\Services\Repository.cs  : Line 570  
   ......

4. Any further technical details

Add any relevant detail that can help us.

@StefH StefH self-assigned this Sep 10, 2023
@StefH
Copy link
Collaborator

StefH commented Sep 10, 2023

Does it work when Subqueryable is a non-generic type?

@StefH StefH added the question label Sep 10, 2023
@zobinlee
Copy link
Author

zobinlee commented Sep 10, 2023

Does it work when Subqueryable is a non-generic type?

this class is written by another coder,i try write a class which inherited this SqlFunc class and add a
method to return this Generic type entity

public static dynamic Subqueryable(Type t)
{
     /// ......
     
     ///......
    return Subqueryable<t>;
}

and parser throw another exception,but i forget the exactly exception message,i need time to re-play this exception .

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