Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Rewritten ADO.NET code based on above remarks, this should be a lot faster. You could still improve by using the ordinal value instead of the column names and by reading the fields in exactly the same order as in the query, but those are micro optimizations.</p> <p>I've also removed a couple of duplications. Y<a href="http://fxcopcontrib.codeplex.com/wikipage?title=DoNotUseParseAndTostringToConvertTypes" rel="nofollow">ou might also want to check how to improve the performance of typecasting and conversions</a>, as the Parse(ToString) route is very inefficient and can cause very strange issues when running with systems running in different languages. There's also a chance of dataloss when doing these conversions when decimal, float or doubles are involved, as not all of their values can be translated to strings correctly (or can't roundtrip back).</p> <pre><code>public static List&lt;NumericFormulaDO&gt; SelectAllNumericFormulas() { var nFormulas = new Dictionary&lt;int, NumericFormulaDO&gt;(); string queryString = @" SELECT * FROM NumericFormula nf Left Join Unit u on u.Unit_Id = nf.Unit_Id Left Join UnitType ut on ut.UnitType_Id = u.UnitType_Id Join RPN r on r.RPN_Id = nf.RPN_Id Join RPNDetails rd on rd.RPN_Id = r.RPN_Id Join Parameter par on par.Parameter_Id = rd.Parameter_Id where nf.NumericFormula_Id&lt;=10000"; using (var connection = new SqlConnection(connectionString)) { connection.Open(); using (var command = new SqlCommand(queryString, connection)); using (var reader = command.ExecuteReader()) { while (reader.Read()) { var det = new RPNDetailsDO(); det.RPNDetails_Id = (int) reader.GetValue("RPNDetails_Id"); det.RPN_Id = (int) reader.GetValue("RPN_Id"); det.Identifier = (string) reader.GetValue("Identifier"); det.Parameter.Architecture = (string)reader.GetValue("Architecture"); det.Parameter.Code = (string)reader.GetValue("Code"); det.Parameter.Description = (string)reader.GetValue("Description"); det.Parameter.Parameter_Id = (int) reader.GetValue("Parameter_Id"); det.Parameter.ParameterType = (string)reader.GetValue("ParameterType"); det.Parameter.QualityDeviationLevel = (string)reader.GetValue("QualityDeviationLevel"); NumericFormulaDO parent = null; if (!nFormulas.TryGetValue((int)reader.GetValue("RPN_Id"), out parent) { parent = CreatingNumericFormulaDO(reader, det); nFormulas.Add(parent.RPN.RPNID, parent); } else { parent.RPN.RPNDetails.Add(det); } } } } return nFormulas.Values.ToList(); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload