Create a method that returns IEnumerable. In this method, the database data and I often pass sqldatareader to the location constructor. So I would have something like this
public static IEnumerable<location> GetLocations() { List<location> retval = new List<location>(); using(sqlconnection conn = new sqlconn(connection string here); { sqlcommand command = new sqlcommand(conn, "spLoadData"); command.commandtype=stored proc SqlDataReader reader = command.executereader(); while(reader.read()) { retval.add(new location(reader)); } } return retval; }
Obviously, the code will not work, but it will just give you an idea.
An ORM converter can save you a lot of time if you have many opportunities to do it!
source share