c# 4.0 - parsing lambdas for dynamic database validation rules -


i have situation i'm needing copy bunch of records 1 database another, , transfer involves lot of transformation. have run case in addition transformation, need validate , reject column values in source data. (for example, i'm dealing weights of dogs , cats, , occasional typos in source data resulted in exorbitant weights incorrect, never validated in source data.) anyway, these exorbitant weights aren't allowed in new database, have identify , set bad values aside.

what want have rule string expression can invoke during transformation. rule stored column mapping instruction. particulars of aren't question, rather how turn plain string expression runtime expression.

(preface: have muddled around lambdas fair amount, tripped time.) here's have.... have isvalid method accepts value sqldatareader. partial class columnrow dataset, , has validationrule string property referenced in code below.

basically, if there no rule specified or if incoming value null, assume it's valid. otherwise, parse lambda validationrule. rule need make work in particular situation "value < 1000"--just give context.

partial class columnrow {     public bool isvalid(object value)     {         if (value == dbnull.value) return true;         if (isvalidationrulenull()) return true;          string exprstring = "value => { return " + validationrule + "; }";         // fails here: no property or field 'value' exists in type 'object'         var expr = system.linq.dynamic.dynamicexpression.parselambda<object, bool>(exprstring);         var method = expr.compile();         return method.invoke(value);     } } 

instead of doing this, add hard-coded criteria source sql statements, stuff rather complicated on sql side i'd rather not modify incoming sql.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -