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 applicable aggregate method 'ContainsKey(String)' exists #494

Closed
daniilzaonegin opened this issue Mar 31, 2021 · 3 comments
Closed

No applicable aggregate method 'ContainsKey(String)' exists #494

daniilzaonegin opened this issue Mar 31, 2021 · 3 comments
Assignees
Labels

Comments

@daniilzaonegin
Copy link

daniilzaonegin commented Mar 31, 2021

In our project we use System.Linq.Dynamic.Core to parse rule expressions from the database.
From DB we get rule with Criteria, that is actually a string expression.
We have a problem, string expression with method ContainsKey is not working.

This is how we parse it

                Expression<Func<DmsDocumentInfo, bool>> filter =
                    DynamicExpressionParser.ParseLambda<DmsDocumentInfo, bool>(
                        ParsingConfig.Default, false, rule.Criteria);

                return filter.Compile().Invoke(documentInfo); //here the error occurs
    public class DmsDocumentInfo
    {
        private const string DOCNUM_KEY = "DOCNUM";
        private const string TYPE_ID_KEY = "TYPE_ID";
        private const string APP_ID_KEY = "APP_ID";
        private const string FORM_KEY = "FORM";

        public DmsDocumentInfo(IReadOnlyDictionary<string, string> properties)
            => Properties = properties ?? throw new ArgumentNullException(nameof(properties));
        
        [JsonProperty("data")]
        public IReadOnlyDictionary<string, string> Properties { get; }
        
        public string DocNumber
            => Properties.TryGetValue(DOCNUM_KEY, out var value) ? value : string.Empty;

        public string TypeId
            => Properties.TryGetValue(TYPE_ID_KEY, out var value) ? value : string.Empty;
        
        public string AppId
            => Properties.TryGetValue(APP_ID_KEY, out var value) ? value : string.Empty;
        
        public string Form
            => Properties.TryGetValue(FORM_KEY, out var value) ? value : string.Empty;

        public override string ToString()
            => string.Join(", ", Properties.Select(p => $"\"{p.Key}\"=\"{p.Value}\""));
    }

rule.Criteria is a string, that contains string expression

rule.Criteria="(TypeId == \"БУХ ОТЧ-ТЬ\" || TypeId == \"КВР.ОТЧ-ТЬ\") && (AppId == \"ACROBAT\" || AppId == \"DOCSIMAGE\" || AppId == \"PKCS\" || AppId == \"TIFF VIEWER\" || AppId == \"WINZIP\") && (Properties.ContainsKey(\"CFM_ORIGINAL_TYPE\") && Properties[\"CFM_ORIGINAL_TYPE\"]!=\"1C\")"

Could you help us and explain why this error happens? IReadOnlyDictionary has method ContaintsKey()...

@StefH
Copy link
Collaborator

StefH commented Mar 31, 2021

@daniilzaonegin
I did a quick test, and with a normal IDictionary<string, string> it works fine.

I'll take a look if this can be fixed.

@daniilzaonegin
Copy link
Author

Thank you! I used another workaround, Properties.Keys.Contains("CFM_ORIGINAL_TYPE") works :)

@StefH
Copy link
Collaborator

StefH commented Apr 1, 2021

OK.

Note that this fix for IReadOnlyDictionary.ContainsKey will be included in next version.

@StefH StefH closed this as completed Apr 1, 2021
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