Created
August 31, 2013 13:05
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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