The string linq query can be entered dynamically, not only by developer. And it should be validated.
Do you have a regex expression or nuget to check if a string is a valid linq expression?
For example for a valid string linq expression :
(a.AccountId== 33
|| a.AccountId == 2
|| a.AccountId == 15) &&
(a.RoleId == 1|| a.RoleId == 3|| a.RoleId == 4)
- Note - It can be also: (It can be each time a different linq query)
(a.TransactionId == 5 && a.EmployeeName == "Tony") || etc..
Example for string that can't be parsed:
(a.AccountId== 33
|| a.AccountId == 2
|| a.AccountId == 15)
(a.a.RoleId == 1|| a.RoleId == 3|| a.RoleId == 4)
Between those 2 , There is no Operator and you can see the a.a. which is invalid and can't be parsed to linq.
15)
(a.a.RoleId == 1||
If someone knows a good C# NuGet like ExpressionEvaluator for .net framework 4.5, Please let me know.
I have used ExpressionEvaluator, Dot net framework 4.5, But it says that this is a valid linq but it's not:
(a.AccountId== 33
|| a.AccountId == 2
|| a.AccountId == 15)
(a.a.RoleId == 1|| a.RoleId == 3|| a.RoleId == 4)
success is true, but it should be false.
success = new CompiledExpression(query);
- Result of a NuGet or Regex
Inside the textbox, Will return Valid:
"(a.ProfileId == 5 && a.ProfileName == 'Alex')"
Invalid: - l.l double l.l is invalid
"l.l.LinkId == 5 || l.LinkName == 'Alex'"
valid and string can be parsed
"l.LinkId == 5 || l.LinkName == 'Alex'"
The parameter l. or a. can be changed to any A-Z I have tried to use DynamicExpresso.Core but i need to specify the parameter.
2条答案
按热度按时间bwleehnv1#
我已经使用动态Express库,创建了一个动态类与属性名称和属性类,通过右x =〉箭头函数参数和我的查询,他们动态类和它的工作. https://www.nuget.org/packages/DynamicExpresso.Core/
flvlnr442#
如果我没理解错的话,您正在搜索使用“IN”关键字(SQL)的LINQ查询。相反,您可以在LINQ中使用Contains。
.NET服务器: