I have this code working:
public IEnumerable<string> GetEmpNames()
{
var cmd = SqlCommand("select [EmpName] from [dbo].[Emp]");
using (var rdr = cmd.ExecuteReader())
while (rdr.Read())
yield return (string) rdr["EmpName"];
}
However, I'm wondering if there's a better (LINQish) way, not having to resort to yield return. (And LINQ to SQL is not an option :) )
IEnumerable<string> result = DataContext.ExecuteQuery<string>(sqlstring)
http://msdn.microsoft.com/en-us/library/bb361109.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With