Lost in composition
-
Sometimes people get a little bit LINQ giddy:-
int fileFormtId = ds.Tables["ExpectedDailyBrokerFiles"].AsEnumerable().Where(x => Fits(Utils.ISS(row["File Name"]), x.Field("Mask")) && x.Field("CHID").HasValue && x.Field("CHID").Value == Utils.ISInt(row["FileSourceID"])).Select(x => x.Field("FileFormatId")).ToList().FirstOrDefault();
-
Sometimes people get a little bit LINQ giddy:-
int fileFormtId = ds.Tables["ExpectedDailyBrokerFiles"].AsEnumerable().Where(x => Fits(Utils.ISS(row["File Name"]), x.Field("Mask")) && x.Field("CHID").HasValue && x.Field("CHID").Value == Utils.ISInt(row["FileSourceID"])).Select(x => x.Field("FileFormatId")).ToList().FirstOrDefault();
Well, if you remove all the other cruft, a
AsEnumerable().Where().Select().FirstOrDefault()
isn't that bad. However,ToList().FirstOrDefault()
is overkill, and with nullable types, why check forHasValue
? MarcLatest Article - Merkle Trees Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802
-
Well, if you remove all the other cruft, a
AsEnumerable().Where().Select().FirstOrDefault()
isn't that bad. However,ToList().FirstOrDefault()
is overkill, and with nullable types, why check forHasValue
? MarcLatest Article - Merkle Trees Learning to code with python is like learning to swim with those little arm floaties. It gives you undeserved confidence and will eventually drown you. - DangerBunny Artificial intelligence is the only remedy for natural stupidity. - CDP1802
..and the mixing type safe and type unsafe field access ..and the fact that it's wrong but I can't see where ..and its a client side join between tables for which a server side view already exists and so on. :-)