dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.27k stars 4.73k forks source link

Cannot evaluate. Expression 'System.Data.NameNode' is not an aggregate #76001

Open viveknuna opened 2 years ago

viveknuna commented 2 years ago

I am trying the evaluate an expression using DataTable, But it's throwing the below exception on line var temp = dt.Compute(formula, filter); I have followed this documentation but it didn't help me.

Cannot evaluate. Expression 'System.Data.NameNode' is not an aggregate

string formula = "(Column * 2)";
DataTable dt = new DataTable();
dt.Columns.Add("Column");

string filter = "Column = 1"
var temp = dt.Compute(formula, filter);

The expected output is 2 here. I have followed this answer. I am just avoiding using any external library. because I tried to Flee library but it's quite unstable.

So if you pass value 3 in place of 1 to this, then it should return 6.

.net framework version: 4.7.2

ghost commented 2 years ago

Tagging subscribers to this area: @roji, @ajcvickers See info in area-owners.md if you want to be subscribed.

Issue Details
I am trying the evaluate an expression using DataTable, But it's throwing the below exception on line v`ar temp = dt.Compute(formula, filter);` I have followed [this](https://learn.microsoft.com/en-us/dotnet/api/system.data.datatable.compute?view=net-6.0) documentation but it didn't help me. Cannot evaluate. Expression 'System.Data.NameNode' is not an aggregate ``` string formula = "(Column * 2)"; DataTable dt = new DataTable(); dt.Columns.Add("Column"); string filter = "Column = 1" var temp = dt.Compute(formula, filter); ``` The expected output is 2 here. I have followed [this](https://stackoverflow.com/a/12431343/6527049) answer. I am just avoiding using any external library. because I tried to Flee library but it's quite unstable. So if you pass value 3 in place of 1 to this, then it should return 6. .net framework version: 4.7.2
Author: viveknuna
Assignees: -
Labels: `area-System.Data`, `untriaged`
Milestone: -
ajcvickers commented 2 years ago

This issue is lacking enough information for us to be able to fully understand what is happening. Please attach a small, runnable project or post a small, runnable code listing that reproduces what you are seeing so that we can investigate.

viveknuna commented 2 years ago

@ajcvickers @roji Above is the complete code, I am again posting with the Main method so that you can just this to any application and reproduce it.

        static void Main(string[] args)
        {
            try
            {
                string formula = "(Column * 2)";
                DataTable dt = new DataTable();
                dt.Columns.Add("Column");

                string filter = "Column = 1";
                var temp = dt.Compute(formula, filter);
            }
            catch (Exception ex)
            {

            }
        }

In short, I am trying to evaluate a mathematical expression by using DataTable here. so (Column * 2) is an expression, so If the Column value is 3, it should return 6. The above is just an example. It could be a complex expression as well. You can refer to this question to understand

There are some libraries that already do this like Flee and NCalc. But I am avoiding using any external library.

I have tried to use DataTable, but it's not working for me.

Is there a way to do this using DataTable or any other way in C#?