Tuesday, 15 September 2015

linq - MVC3 dynamic number of checks in where clause -


In my opinion, I have several selections with a list of server names. The number of servers will be dynamic and will change quite a bit. .

  & lt; Select name = "server" class = "selectioncucker" multiple data-live-search = "true" & gt; & Lt; Optgroup label = "prod5" & gt; & Lt; Options & gt; VS12 & lt; / Options & gt; & Lt; Options & gt; ... & lt; / Options & gt; & Lt; / Optgroup & gt; & Lt; Optgroup label = "UAT6" & gt; & Lt; Options & gt; VS13 & lt; / Options & gt; & Lt; Options & gt; ... & lt; / Options & gt; & Lt; / Optgroup & gt; & Lt; / Select & gt; In the controller I need a filter for some static number against the KPIK and DNA server name (KPI.KPIserver), which will be selected by the user from multiple selections. How to add in the way given below, where the directive number of the clause is checked in the KPISarver, e.g.  

Where kpi.KPIkey == "CPU Usage" || Kpi.KPIkey == "I / O Operation" & amp; Amp; Kpi.KPIserver == "VS12" || || Kpi.KPIserver == "VS13" || Kpi.KPIserver == ...

  [HTTP post] Public Performance Index (FormCollection FS) {INMERABLE & lt; Kpi_master & gt; AllKPI = Faucet; Try kpi in {AllKPI = db.kpi_masters where kpi.KPIkey == "CPU Usage" || Kpi.KPIkey == Choose "I / O operation" copy; } Hold (exception e) {log. Error ("KPI Post Error:" + E. Message); } View return (allKPI); }  

If you have a certain field being checked, then it is easy enough .

  var key = new list & lt; String & gt; () {"CPU Usage", "I / O Action"}; Var Server = New List & lt; String & gt; () {"VS 13", "SERVERX"}; ..... allKPI = allKPI = DP.PPI_Master's whereby keys from kPI.Compatible (kpi.KPIkey) || Server. (Kpi.KPIserver) includes kpi;  

No comments:

Post a Comment