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

Like Operator: Unable to load one or more of the requested types. #726

Open
Trevortni opened this issue Aug 1, 2023 · 2 comments
Open

Comments

@Trevortni
Copy link

1. Description

When attempting to use the Like operator as such:

string whereRequest = string.Join(" or ", columns.Select(col => $"DynamicFunctions.Like(Convert.ToString({col}).ToLower(), \"%{term.ToLower()}%\"");
var count = await MyObject.Where(new ParsingConfig { ResolveTypesBySimpleName = true }, whereRequest).CountAsync();

I get the following exception

2. Exception

Exception message:
System.Reflection.ReflectionTypeLoadException: 'Unable to load one or more of the requested types.
Could not load type 'Microsoft.EntityFrameworkCore.Metadata.RelationalModelAnnotations' from assembly 'Microsoft.EntityFrameworkCore.Relational, Version=7.0.5.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
Could not load type 'Microsoft.EntityFrameworkCore.Metadata.RelationalPropertyAnnotations' from assembly 'Microsoft.EntityFrameworkCore.Relational, Version=7.0.5.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
Could not load type 'Microsoft.EntityFrameworkCore.Metadata.Internal.RelationalFullAnnotationNames' from assembly 'Microsoft.EntityFrameworkCore.Relational, Version=7.0.5.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.'

Stack trace:
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.Assembly.GetTypes() in /_/src/libraries/System.Private.CoreLib/src/System/Reflection/Assembly.cs:line 71
   at System.Linq.Dynamic.Core.CustomTypeProviders.AbstractDynamicLinqCustomTypeProvider.ResolveTypeBySimpleName(IEnumerable`1 assemblies, String simpleTypeName)
   at System.Linq.Dynamic.Core.CustomTypeProviders.DefaultDynamicLinqCustomTypeProvider.ResolveTypeBySimpleName(String simpleTypeName)
   at System.Linq.Dynamic.Core.Parser.TypeFinder.ResolveTypeByUsingCustomTypeProvider(String name, Boolean forceUseCustomTypeProvider)
   at System.Linq.Dynamic.Core.Parser.TypeFinder.FindTypeByName(String name, ParameterExpression[] expressions, Boolean forceUseCustomTypeProvider)
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseAsEnum(String id)
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseMemberAccess(Type type, Expression expression)
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParseIdentifier()
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParsePrimaryStart()
   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.ParseParenExpression()
   at System.Linq.Dynamic.Core.Parser.ExpressionParser.ParsePrimaryStart()
   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, Boolean createParameterCtor, ParameterExpression[] parameters, Type resultType, String expression, Object[] values)
   at System.Linq.Dynamic.Core.DynamicExpressionParser.ParseLambda(ParsingConfig parsingConfig, Boolean createParameterCtor, Type itType, Type resultType, String expression, Object[] values)
   at System.Linq.Dynamic.Core.DynamicQueryableExtensions.Where(IQueryable source, ParsingConfig config, String predicate, Object[] args)
   at System.Linq.Dynamic.Core.DynamicQueryableExtensions.Where[TSource](IQueryable`1 source, ParsingConfig config, String predicate, Object[] args)
   at DatabaseContexts.Controllers.DataControllers.ListablesControllerLight`2.<GetSearchListLength>d__18.MoveNext() in C:\Users\lewisw\source\repos\dsd-api\DSD-Web-API\Controllers\DataControllers\ListablesController.cs:line 238

3. Fiddle or Project

Will attempt to further isolate issue tomorrow.

4. Any further technical details

Using Npgsql.EntityFrameworkCore.PostgreSQL 7.0.4 and EntityFrameworkCore 7.0.9

@rowanfreeman
Copy link

I don't get that exception but I get a different one.

System.Linq.Dynamic.Core.Exceptions.ParseException: 'No applicable method 'Like' exists in type 'DynamicFunctions"

Screenshot 2023-09-22 104408

The interesting thing is that I'm also using Npgsql. I wonder if the two things are related?

  • NpgsqI.EntityFrameworkCore.PostgreSQL 7.0.4
  • Microsoft.EntityFrameworkCore 7.0.10
  • Microsoft.EntityFrameworkCore.DynamicLinq 7.3.5

@lukasf
Copy link

lukasf commented Feb 5, 2024

Has anyone ever got this to work? Being able to use the "LIKE" operator is a very important scenario.

Getting the same error as the previous answer:

System.Linq.Dynamic.Core.Exceptions.ParseException: 'No applicable method 'Like' exists in type 'DynamicFunctions"

When I open the source, I see the Like function is commented out. I tried to implement the class locally, exactly like in DynamicFunctions, but then the expression cannot be translated to SQL (because it passes my local method down to EF, instead of the EF.Functions one).

I also tried to use EF.Functions or DbFunctions.Instance, but that also does not seem to work. It always complains like "enum not found". Dynamic Linq does not seem to support static properties?

Has anyone found a way to do this? CustomTypeProvider or any other solution/hack?

  • Microsoft.EntityFrameworkCore.SQLite 7.0.14
  • Microsoft.EntityFrameworkCore 7.0.14
  • Microsoft.EntityFrameworkCore.DynamicLinq 7.3.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants