Building a collection of business categories in C# without a DB – Education Career Blog

This is a two part question really (at the end).

Let’s say I have a DB table of businesses. Each business has a category field, filled with a category “slug” (food-restaurant-brazilian for example). Instead of building a BusinessCategory DB table, I’m just going to build it in-code. Something like this:

public class BizCategory {
  public string Slug {get; set;}
  public string Name {get; set;}
  public string Icon {get; set;}
  public string Description {get; set;}
  ...

  public IQueryable<BizCategory>() AllCategories {
    List<BizCategory> bizCatList = new List<BizCategory>();
    bizCatList.Add(new BizCategory { Slug = "food-restaurant-brazilian", Name = "Brazilian Restaurant", Icon = "icon.png", Description = "Places to eat Brazilian food"});
    bizCatList.Add(new BizCategory { Slug = "food-restaurant-italian", Name = "Italian Restaurant", Icon = "icon.png", Description = "Places to eat Italian food"});
    bizCatList.Add(new BizCategory { Slug = "food-restaurant-japanese", Name = "Japanese Restaurant", Icon = "icon.png", Description = "Places to eat Japanese food"});
    ...

    return bizCatList.AsQueryable<BizCategory>();
  }
}

Then whenever I need the name of a category, by it’s slug I could call BizCategory.AllCategories().Where(c => c.Slug == "food-restaurant-brazilian").First().Name;

Instead of hitting the DB, it would be from an in-memory collection. The idea is to reduce table joins and network latency to increase performance of my site. One issue I see would be that category changes would need to be done in code, harder to change on the fly.

1) Have you done this before? Any particular issues that I should look out for?

2) Do you know of a source for a good list of business categories? Perhaps similar to the list of ad categories on eBay classifieds, but tailored for business types.

,

If you already have a DB, then you might as well create a table for the business categories. That said you can just read it in once on startup and use a collection of some sort as you’ve mentioned.

As for the category lists, http://www.google.com/Top/Business/ is a good place to start.

Good luck.

,

I suggest you to go for Dictionary.

Dictionary<string, string> d = new Dictionary<string, string>();
        d.Add("food-restaurant-brazilian", "Brazilian Restaurant");
        d.Add("food-restaurant-italian", "Italian Restaurant");
        d.Add("food-restaurant-japanese", "Japanese Restaurant");

Leave a Comment