Skip to content

Instantly share code, notes, and snippets.

@kosperera
Created August 31, 2013 13:05
Show Gist options
  • Save kosperera/6398062 to your computer and use it in GitHub Desktop.
Save kosperera/6398062 to your computer and use it in GitHub Desktop.
Blogged : Yet another ORM - Code snippet 1 The old-school mapping query results to POCO.
using (IDataReader reader = command.ExecuteReader())
{
List<Category> cats = new List<Category>();
while (reader.Read())
{
int idOrdinal = reader.GetOrdinal("cid");
int nameOrdinal = reader.GetOrdinal("name");
if (!reader.IsDBNull(idOrdinal))
{
Category category = new Category
{
Id = reader.GetInt32(idOrdinal),
Name = reader.GetString(nameOrdinal)
};
cats.Add(category);
}
}
return cats;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment