this is my first post.
I am selecting some fields from a database which are numeric id values e.g. 10,20,100,110 etc. These numbers actually mean something meaningful such as area. Ideally there should be a look up database table with matching ID and name field but there isnt and it has now become difficult to implement in a reasonable timescale (politics).
I currently use a cumbesome switch function to check the id and return the relevent text.
private string GetUnitName(string areaid)
{
string areaName = string.Empty;
switch (areaid.Trim())
{
case "10":
areaName = "area 1";
break;
case "20":
areaName = "area 2";
break;
case "30":
areaName = "area 3";
break;
}
return areaName ;
}
I cant get them in a dateabse so what is the best way to store these area strings?
Can I group them in a settings file or something?
Thanks for listening
As an Enum you’d have to recompile if you ever needed to change them (depends how often they change)?
Alternatively you could just have a XML Document that you could stash in the Cache and XPath it to find the text for the id?
Set the Cache Dependancy to expire if the file is changed then when you update it you won’t have to restart anything. For speed you could read this into memory as a hash so you don’t have to keep XPathing the doc all the time too.