I have this code that works, but I'm sure that it can be done better, any suggestions?
Dictionary<string, StrainGroupings> GetOperationStrainGroupings(string locale)
{
var result = new Dictionary<string, StrainGroupings>();
try
{
Open();
setDatabaseTables();
result = Connection.Table<StrainGroupings>()
.Where(sg => sg.Locale == locale)
.Join(Connection.Table<OperationStrainGroups>(),
strainGrouping => strainGrouping.StrainGroupName,
operationStrainGroup => operationStrainGroup.StrainGroupName,
(strainGrouping, operationStrainGroup) => new { Name = operationStrainGroup.OperationName.Distinct(), sg = strainGrouping })
.AsEnumerable()
.ToDictionary(row => row.Name.ToString(), row => row.sg);
}
catch (Exception ex)
{
throw new ApplicationException("Error retrieving operation strain groupings", ex);
}
finally { Close(); }
return result;
}
It is part of a method that returns a Dictionary(). The idea is return result, as it is dealing with a sQLite Database, it is in a try/catch/finally. That's why I'm not returning result directly, I need to close the database first and maybe dealing with exceptions.
StrainGroupings
etc.) and approx. number of records. Performance problems tend to be very hard to tackle without lots of internal details. Meaning: it tends to be impossible. \$\endgroup\$