public IEnumerable <ICategory> GetCategories() { var result = new List <Category>(); using (var connection = new SqlConnection(_connectionData.GetConnectionString())) { var command = new SqlCommand("Select * from Category", connection); command.CommandType = CommandType.Text; connection.Open(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { var data = new object[reader.FieldCount]; reader.GetValues(data); result.Add(new Category() { CategoryId = int.Parse(data[0].ToString()), CategoryName = data[1].ToString() }); } connection.Close(); } return(result); }
public IEnumerable <ICategory> GetCategories() { var db = new DataContext(_connectionData.GetConnectionString()); var query = from category in db.GetTable <DbCategory>() select category.ConvertToCategory(); return(query); }
public EfDataProvider(IConnectionData connectionData) { _dbContext = new WebShopItemsContext(); _dbContext.Database.SetConnectionString(connectionData.GetConnectionString()); _dbContext.Database.EnsureCreated(); }