public bool UserExists(string login)
 {
     using (var context = new DemoContext())
     {
         return context.Users.Any(u => u.Login == login);
     }
 }
 public List<Country> GetCountries()
 {
     using (var context = new DemoContext())
     {
         return context.Countries.AsNoTracking().ToList();
     }
 }
 public List<Province> GetProvincesByCountryName(string country)
 {
     using (var context = new DemoContext())
     {
         return context.Provinces
             .AsNoTracking()
             .Include(p => p.Country)
             .Where(p => p.Country.Name == country)
             .ToList();
     }
 }
        public void AddUser(string login, string password, string country, string province)
        {
            using (var context = new DemoContext())
            {
                var provinceEntity = context.Provinces
                    .SingleOrDefault(p => p.Name == province && p.Country.Name == country);

                if (provinceEntity == default(Province))
                {
                    throw new InvalidOperationException("Missing country and province combination");
                }

                context.Users.Add(new User() { Login = login, Password = password, Province = provinceEntity });
                context.SaveChanges();
            }
        }