This question already has answers here:
How can I evaluate a C# expression dynamically?
(9 answers)
Closed 3 years ago.
So basically what i have been struggling with is to evaluate sentence in EF Core.
For example if i have:
string condition = "65 < 100 AND 65 > 50"
How can evaluate that?
You can execute SQL String in EF Core, So what you need is to write the whole SQL you want in a sctring and then concatenate this part to it. after that you execute it like this
myDbContextObject.Database.ExecuteSqlCommand(sqlString,params[]);
OR
myDbContextObject.Table.FromSql(sqlString,params[]);
Related
This question already has answers here:
Remove dots from the path in .NET
(10 answers)
Closed 1 year ago.
Is there a built in way of removing unnessacary statements like this \hello\.. from a path in C# or do I have to do this using regex replace?
Example:
C:\Users\me\myfolder\..\anotherFolder\image.png to C:\Users\me\anotherFolder\image.png
C:\Users\me\myfolder\..\..\you\f\image.png to C:\Users\you\f\image.png
my solution using regex would be removing this /\\([^\.\\]+)\\\.\./ using a loop regexr.com
You should just be able to write this:
string fixedPath = Path.GetFullPath(#"C:\Users\me\myfolder\..\anotherFolder\image.png"));
Result in fixedPath:
C:\Users\me\anotherFolder\image.png
This question already has answers here:
Evaluating string "3*(4+2)" yield int 18 [duplicate]
(13 answers)
Is there a string math evaluator in .NET?
(18 answers)
Closed 4 years ago.
I have one scenario in C#, which I fetch the expression from database, I need to parse and evaluate the same
The expression can be of any type (With + & - Operator only) as mentioned below
X+Y-Z
X-Y-Z
Z-Y+Z
Where as at run time I have any of above expression as string item and the values for each variable defined in it.
Now I need to automate the same, so that my code at run time will able to parse and evaluate the same.
I believe Switch case and if/else loop is the one way, but any can please suggest some other better and efficient way.
Thanks in advance
This question already has answers here:
Regular expression to extract text between square brackets
(15 answers)
Closed 5 years ago.
string subject = "Re: Customer request [#11#]";
I want to fetch [#11#] from the above string. At run time instead of 11 there can be any number e.g. 12,13,14 etc.
Please suggest me appropriate Regex to fetch this output.
Something like this: \[#\d{0,}#\]
You can fiddle with it on https://regex101.com/r/uA8fX9/3
This question already has answers here:
Like in Lambda Expression and LINQ
(6 answers)
Closed 5 years ago.
I'm trying to filter out results based on an input string, and I need to use SQL LIKE operation for that and not a normal comparison. Couldn't find the solution online(probably didn't use the correct search words) :
return _context.Cities.Where(t => t.Name == cityName);
And I need it to do WHERE t.name LIKE '%CityName%' . How do I simulate it here ?
_context.Cities.Where(t=> t.Name.Contains(cityName));
This question already has answers here:
Serializing and Deserializing Expression Trees in C#
(7 answers)
Is it possible to dynamically compile and execute C# code fragments?
(7 answers)
Closed 7 years ago.
I wonder if it is possible to convert text to C# code for dynamic validation. For example, I'd love to be able to store a string in my DB like this:
((Value.StartsWith("CR") || Value.StartsWith("TRC")) && Value.Length == 10)
Then - pull it from the DB and use it to validate data. If would automatically swap out Value for the piece of data I'm trying to validate.
All validations would return a boolean that I would use in the code to see if the data being tested passed or failed.
I would have numerous variations of validations similar to the one above like this stored in my DB.
I've tried researching various phrases on Google but can't seem to think of what this might be called?