public static IEnumerable <Category> GetAllCategories() { using (var connection = new MySqlConnection(connectionString)) { connection.Open(); string mysqlexpression = "SELECT * FROM Category"; using (MySqlCommand command = new MySqlCommand(mysqlexpression, connection)) { MySqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { yield return(new Category() { IdCategory = reader.GetInt32("idCategory"), Name = reader.GetString("category"), Product = GoodsDb.GetProductById(reader.GetInt32("Goods_idGoods")) }); } } } } }
public static IEnumerable <CustomersGoods> GetCustomerGoods() { using (var connection = new MySqlConnection(connectionString)) { connection.Open(); string mysqlexpression = "SELECT * FROM Customers_has_Goods"; using (MySqlCommand command = new MySqlCommand(mysqlexpression, connection)) { MySqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { yield return(new CustomersGoods { Customer = CustomerDb.GetCustomerById(reader.GetInt32("Customers_idCustomers")), Product = GoodsDb.GetProductById(reader.GetInt32("Goods_idGoods")) }); } } } } }