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

No property or field 'DynamicFunctions' exists in type #483

Closed
Euynac opened this issue Feb 10, 2021 · 5 comments
Closed

No property or field 'DynamicFunctions' exists in type #483

Euynac opened this issue Feb 10, 2021 · 5 comments
Labels

Comments

@Euynac
Copy link

Euynac commented Feb 10, 2021

I want to use Like function in Where clause in dynamic way, and I have included the NuGet Microsoft.EntityFrameworkCore.DynamicLinq, System.Linq.Dynamic.Core, and EFCore 3.1
I simply test it like:

                using (var context= new KouContext())
                {
                    context.UserBlacklist.Where(ParsingConfig.DefaultEFCore21,"DynamicFunctions.Like(Reason, \"test%\")");
                }

But I only got the exception Unhandled exception. No property or field 'DynamicFunctions' exists in type 'UserBlacklist' (at index 0)
I have tried to replace DynamicFunctions with DbFunctionsExtensions or others, but got the same Exception No property or field.
I even write a member in to dbModel:

        [NotMapped]
        public DynamicFunctionsClass DynamicFunctionsBridge;
        [NotMapped]
        public class DynamicFunctionsClass
        {
            public bool Like(string matchExpression, string pattern) => DynamicFunctions.Like(matchExpression, pattern);
        }

but it give me the another exception: could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync().

I also have scrutinized the issue #105 and tried as much as I could but in vain
maybe it's my fault to use it in wrong way? Hope someone could tell me how to use it correctly! Thanks a lot!

@Euynac
Copy link
Author

Euynac commented Feb 10, 2021

Sorry I didn't see the issue #396 , but I'm still confused that how to implement 'Like' function in dynamic linq way on EFCore 3.0 or newer? I don't want to use Contains or StartWith..

@Euynac Euynac closed this as completed Feb 15, 2021
@StefH StefH added the question label Feb 15, 2021
@jacobSpitzer
Copy link

I have the same problem.
using EF6, ASP.NET CORE 3.1
trying to figure out a long time how to use LIKE with DynamicFunctions, but not found any solution so far.

StefH Please help me using your great open source functionality

Euynac Please let me know what was your solution at the end.

@Euynac
Copy link
Author

Euynac commented Mar 5, 2021

@jacobSpitzer Actually I didn't find a solution using in server evaluation, so I finally switched to Explicit client evaluation.
If you can accept this, you can use DynamicLinqTypeAttribute in a custom static class, and put Like method in it like this:

[DynamicLinqType]
    public static class KouDynamicFunctions
    {
        public static bool Like(string fieldContent, string inputPattern) => DynamicFunctions.Like(fieldContent, inputPattern);
    }

And the dynamic string you can write like this:

list.Where("{nameof(KouDynamicFunctions)}.{nameof(KouDynamicFunctions.Like)}({fieldName}, @{num})");

@Euynac
Copy link
Author

Euynac commented Mar 5, 2021

maybe you can't use dynamic linq in list...? Sorry I forgot... I first change the dynamic expression into predicate, and then the list use the generated predicate.

public static Predicate<T> GeneratePredicateGeneric<T>(string fieldExpressions, object[] fieldValues)
        {
            return ((Func<T, bool>)DynamicExpressionParser
                .ParseLambda(typeof(T), typeof(bool), fieldExpressions, fieldValues).Compile()).Invoke;
        }

@AryaPry
Copy link

AryaPry commented Jan 24, 2024

how to solve system.Linq.Dynamic.Expection'No proerty or fields'ideas' exist in type 'Customer'
Can you please help me

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

4 participants