public static void ReadCards(int house) { string queryString = "select card_id, card_title, st_title, cult_id, optimal, tolerance, limit_dev from cards natural join stages natural join plants where house_id=@house_id"; using (NpgsqlConnection connection = new NpgsqlConnection(ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString)) { NpgsqlCommand command = new NpgsqlCommand(queryString, connection); command.Parameters.AddWithValue("@house_id", house); connection.Open(); NpgsqlDataReader reader = command.ExecuteReader(); try { while (reader.Read()) { Card new_Card = new Card { Card_id = (int)reader[0], Title = reader[1].ToString(), Stage = reader[2].ToString(), Cult_id = (int)reader[3], Optimal = (float)reader[4], Tolerance = (float)reader[5], Limit_deviation = (float)reader[6] }; if (Plants.First() != null) { Plants.Where(p => (p.Cult_id == new_Card.Cult_id) && (p.Stage_id.Title == new_Card.Stage)).First().Cards_of_plant.Add(new_Card); } Cards.Add(new_Card); new_Card = null; } } finally { reader.Close(); } } }