存储和解析数据库布尔表达式 [英] storing and parsing boolean expressions in database

查看:298
本文介绍了存储和解析数据库布尔表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我刚才的问题一个后续问题它的设计模式是适合这个工作流程要求?。我想知道什么是存储在数据库中的布尔表达式,然后在运行时不费力评价它最好的方式。我有一个要求,其中一组作业需要从每月底屏幕,可以执行的作业是否依赖于以前的工作成果的决定执行。所以我应该能够保存在数据库中像E =(A或B)和(C或D)的表达式(可以是任意复杂的嵌套表达式)。这意味着E能够运行,如果A或B是成功的,C或D是成功的。这怎么能在数据库中表示,并解析和条件后评估?

this is a follow-up question for my previous question which design pattern is suitable for this workflow requirement?. I would like to know what is best way to store a boolean expression in database and then evaluate it at runtime without much effort. I have a requirement where a set of jobs need to be executed from the screen every month-end and the decision of whether a job can be executed depends on the outcome of previous jobs. so I should be able to save an expression in database something like E = (A or B) and (C or D) (could be any complex nested expression). which means E can run if A or B is successful and C or D is successful. how can this be represented in database and parsed and condition be evaluated later?

做这样的(未测试)

,如果思维作业E =(A和B)或(C和D)。其存储为一个树形结构表中的

thinking of doing it like this (not tested yet)
if "Job E = (A and B) or (C and D)". store it as a tree structure in the table


JobId DependentJobId SuccessJobId FailureJobId
E        A             B             C              
E        C             D             0
E        D             1             0
E        B             1             0

这意味着如果A成功,请检查b,否则检查C,如果C成功检查D。过程从最高点这是任何DependentJobId开始,在叶节点停止。我用假作业ID1的成功和0的失败。如果叶节点是零,则作业允许运行。不知道如何最好能在T-SQL评估此。我可能不得不使用递归函数

this means "if A is successful, check B else check C", "if C is successful check D". process starts from highest node which no "DependentJobId" and stops at leaf node. I use dummy Job Ids "1" for success and "0" for failure. if the leaf node is zero, then job is allowed to run. not sure how best I can evaluate this in T-sql. I may have to use a recursive function.

技术:ASP.NET 3.5,C#3.0,SQL Server 2008中

Technology to be used: ASP.NET 3.5, C# 3.0, SQL Server 2008

推荐答案

我解决它使用我在问题中提到的方法。虽然这是不好把业务规则在一个表中,我需要这种快速而维护的解决方案,所以我选择了这个。如果我的工作依赖存储在一个表中,我可以改变很容易不改变,一旦它进入到生产,这是有用的代码。我写了一个递归函数通过作业依赖图行走,并确定结果。感谢您的答复。

I solved it using the approach I mentioned in the question. though it is not good to put the business rules in a table, I needed a quick but maintainable solution for this, so I chose this. if I store the job dependencies in a table, I can make changes to it easily without changing the code which is useful once it goes to production. I have written a recursive function to walk through the job dependency graph and determine the result. thanks for all your replies.

这篇关于存储和解析数据库布尔表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆