简体   繁体   English

数学表达评估

[英]Mathematical expression evaluation

I've got a question about expression evaluation from string. 我有一个关于字符串的表达式求值的问题。 Currently I'm working on project that requires to calculate mathematical expressions from strings that are stored in DB, I want to make C# method that evaluate this string, and this function will be run from stored procedure or function added to DB. 目前,我正在研究需要从存储在数据库中的字符串中计算数学表达式的项目,我想使用C#方法来评估此字符串,并且此函数将从存储过程或添加到数据库的函数中运行。 So the problem is that I want to use in my C# function already created solutions like NCalc or Jace.Net, but if I want to run it from db I need to add dlls(for example NCalc.dll or Jace.dll) to db assembly. 所以问题是我想在我的C#函数中使用已经创建的解决方案,例如NCalc或Jace.Net,但是如果我想从db运行它,则需要向db中添加dll(例如NCalc.dll或Jace.dll)部件。 And adding those solutions are quite problematic, NCalc use unsafe code and Sql server cannot run methods from this dll, while Jace need many additional dlls that needs to be added to DB, this is not acceptable solution. 并且添加这些解决方案是很成问题的,NCalc使用不安全的代码,并且Sql Server无法从该dll运行方法,而Jace需要将许多其他dll添加到数据库中,这是不可接受的解决方案。 So if any one knows working expression evaluator that can be added to db and run ? 因此,是否有人知道可以添加到db并运行的工作表达式评估器? Thx in advance for help. 提前寻求帮助。

I'm using Microsoft SQL Server 2012 (SP1) - 11.0.3128.0 (X64) 2) and .Net framework 4.5 我正在使用Microsoft SQL Server 2012(SP1)-11.0.3128.0(X64)2)和.Net Framework 4.5

A. I think you could include embed JavaScript engines to the circle of your interests.. 答:我认为您可以将JavaScript引擎嵌入您的兴趣范围。

eg http://jurassic.codeplex.com/ - pure dotnet, one dll, easy as pie (but still requires WITH PERMISSION_SET = UNSAFE/EXTERNAL_ACCESS, and I think any not specially desigden for CLR lib would require UNSAFE, eg it is enough to have static not-readonly field to became UNSAFE, other restrictions: http://msdn.microsoft.com/en-us/library/ms403273.aspx ). 例如http://jurassic.codeplex.com/-纯dotnet,一个dll,很容易做馅饼(但仍然需要WITH PERMISSION_SET = UNSAFE / EXTERNAL_ACCESS,我认为对于CLR lib没有特别设计的任何东西都需要UNSAFE,例如,就足够了要使静态非只读字段成为UNSAFE,其他限制如下: http : //msdn.microsoft.com/en-us/library/ms403273.aspx )。

B. Don't forget that T-SQL is dynamic language as well. B.不要忘记T-SQL也是动态语言。 Why you can't just save your expressions in T-SQL ? 为什么不能只在T-SQL中保存表达式? IMHO Sql Server much more suitable to run "Avg" than any expression evaluator that can be called throug CLR drain. IMHO Sql Server比任何可以通过CLR Drain调用的表达式评估器更适合运行“ Avg”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM