So I have a list that comes from a database on which I'm using linq to find items and here's how i do it:
public static List<myEntity> GetEntities()
{
List<myEntity> result = new List<myEntity>();
var entities = _data.AsEnumerable()
.Where(ent => ent.Field<string>(Constants.MODEL_DESC).Split(';')[0] == Constants.MODEL_ENTITY);
foreach (var entity in entities)
{
myEntitytemp = new myEntity();
string[] zzzDESC = entity.Field<string>(Constants.MODEL_DESC).Split(';');
temp.ID = Convert.ToInt16(zzzDESC[1]);
temp.icon = zzzDESC[2].Replace(".bmp", "");
temp.Translations = GetTranslation(Convert.ToInt16(zzzDESC[1]));
temp.tableName = GetTableName(temp.ID);
temp.attributes = GetAttributes(temp.ID);
result.Add(temp);
}
return result;
}
So basically there are 3 columns in my table and 1 of them stores the useful data separated by ";". Inside this function i have GetTableName (returns a string) and GetAttributes (return a list of class Attribute) and GetTranslations() in which i'm using the same kind of logic that in this method GetEntities().
private static List<Translation> GetTranslation(int id)
{
List<Translation> result = new List<Translation>();
var translations = _data.AsEnumerable()
.Where(trl => trl.Field<string>(Constants.MODEL_DESC).Split(';')[0] == Constants.MODEL_TRANSLATION)
.Where(trl => trl.Field<string>(Constants.MODEL_DESC).Split(';')[2] == id.ToString());
foreach(var trl in translations)
{
Translation temp = new Translation();
string[] ZZZDesc = trl.Field<string>(Constants.MODEL_DESC).Split(';');
temp.ID = Convert.ToInt16(ZZZDesc[1]);
temp.ParentID = Convert.ToInt16(ZZZDesc[2]);
temp.Language = (Language)Convert.ToInt16(ZZZDesc[3]);
temp.ShortName = ZZZDesc[4];
temp.LongName = ZZZDesc[5];
temp.HelpID = ZZZDesc[6];
temp.Description = ZZZDesc[7];
result.Add(temp);
}
return result;
}
They all query the same data which in this case is _data. It's a DataTable. And i can already notice that the process is very long. Pretty sure it's because i have to query the same table over and over to find what i'm searching for. The table itself has around 8000 rows so it's not that much.
I thought i may delete the rows once i got my stuff, i don't know if that a good idea since i will have to find the rows i was working with so that's 1 more entrance in _data per function and then delete it. Or maybe do it with linq if it's possible? and do it at the same time as i'm constructing the var entities, var translations, and so on.
Or is it just my way of working with linq that's the problem?