Repository navigation
Unrecognize the Generic Type when parse the lambda expression string #742
Copy link
Copy link
Open
Labels
Description
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.
Reactions are currently unavailable
Activity
StefH commentedon Sep 10, 2023
Does it work when
Subqueryableis a non-generic type?zobinlee commentedon Sep 10, 2023
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
and parser throw another exception,but i forget the exactly exception message,i need time to re-play this exception .