Oh I wish this were using an ORM. These are POCOs that end up getting sent to a stored procedure to update the database. Looking past using for instead of foreach and then the fun continue in the loop instead of just inverting the if, but hitting the db again and mapping the results back into the object just to end up with what was already there is pretty inexcusable.
Dinkus
@Dinkus
Best posts made by Dinkus
Latest posts made by Dinkus
-
RE: Found in production codebase
-
Found in production codebase<font size="3" face="Times New Roman">posted in Side Bar WTF
</font>
<font size="3"><font face="Calibri">Foo parentFoo =
<font size="3" face="Times New Roman">
GetFooFromDbById(parentFooId);<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p></font></font></font>
<font size="3"><font face="Calibri">List<Foo> foos =
<font size="3" face="Times New Roman">
GetFoosFromDbByBatch(parentFoo.BatchId);<o:p></o:p></font></font></font>
<o:p><font size="3" face="Calibri"> </font></o:p>
<font size="3" face="Times New Roman"></font>
<font size="3"><font face="Calibri">for (int i = 0; i <
<font size="3" face="Times New Roman">
foos.Count(); i++)<o:p></o:p></font></font></font>
<font size="3"><font face="Calibri">{<o:p></o:p></font></font>
<font size="3" face="Times New Roman"></font>
<font size="3"><font face="Calibri">
<font size="3" face="Times New Roman">
if (foos[i].Bar == parentFoo.Bar) continue;<o:p></o:p></font></font></font>
<font size="3"><font face="Calibri">
<font size="3" face="Times New Roman">
foos[i] = GetFooFromDbById(foos[i].Id);<o:p></o:p></font></font></font>
<font size="3"><font face="Calibri">
<font size="3" face="Times New Roman">
foos[i].Bar = parentFoo.Bar;<o:p></o:p></font></font></font>
<font size="3"><font face="Calibri">
<font size="3" face="Times New Roman">
SaveFooToDb(foos[i]);<o:p></o:p></font></font></font>
<font size="3"><font face="Calibri">}<o:p></o:p></font></font>
<font size="3" face="Times New Roman"> </font>