Skip to content

Instantly share code, notes, and snippets.

@mrstebo
Created June 2, 2020 12:04
Show Gist options
  • Select an option

  • Save mrstebo/b35d8c15fe72d40ff1d2a3e749583d2b to your computer and use it in GitHub Desktop.

Select an option

Save mrstebo/b35d8c15fe72d40ff1d2a3e749583d2b to your computer and use it in GitHub Desktop.
hello-entity-framework-1
public class UserService
{
public IEnumerable<User> GetUsers()
{
var ds = new DataSet();
using (var con = new SqlConnection("Server=myServerAddress;Database=myDataBase;UserId=myUsername;Password=myPassword;"))
{
using (var da = new SqlDataAdapter("SELECT * FROM Users", con))
{
da.Fill(ds);
}
}
if (ds.Tables.Count == 0)
return new User[] { };
return ds.Tables[0].Rows.Cast<DataRow>().Select(x => new User
{
Id = (long) x["ID"],
Username = (string) x["Username"],
Password = (string) x["Password"]
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment