Exemple #1
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            CapitalCity c = obj as CapitalCity;

            if (c == null)
            {
                return(false);
            }

            return(this.Id == c.Id);
        }
Exemple #2
0
        public object GetCountyAndItsCapitalCityDDetails(int countryId)
        {
            using (SQLiteConnection con = new SQLiteConnection("Data Source = C:\\Users\\User\\Desktop\\SQLite\\30.db; Version = 3;"))
            {
                con.Open();

                using (SQLiteCommand cmd = new SQLiteCommand($"SELECT *, Country.name as nameOfCountry, CapitalCity.name as nameOfCapitalCity FROM Country JOIN CapitalCity ON Country.CapitalCity_id ==CapitalCity.id WHERE Country.id = {countryId}", con))
                {
                    using (SQLiteDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            Country c = new Country
                            {
                                Id            = (int)reader["id"],
                                Name          = (string)reader["nameOfCountry"],
                                SizeKm        = (int)reader["size_km"],
                                BithYear      = (int)reader["bith_year"],
                                CapitalCityId = (int)reader["CapitalCity_id"],
                            };

                            CapitalCity cc = new CapitalCity
                            {
                                Id          = (int)reader["id"],
                                Name        = (string)reader["nameOfCapitalCity"],
                                NumCitizens = (int)reader["NumCitizens"],
                                CountryId   = (int)reader["Country_id"],
                            };

                            var result = new
                            {
                                Country         = c.Name,
                                IdOfCapitalCity = cc.Id,
                                CapitalCity     = cc.Name,
                                NumCitizens     = cc.NumCitizens,
                                IdOfCountry     = cc.CountryId
                            };

                            con.Close();
                            return(result);
                        }
                    }
                }
            }
            return(null);
        }