/// <summary>
 /// Cached Map.
 /// </summary>
 private static void CacheThreadMap()
 {
     using (MapContext connection = new MapContext())
     {
         var entity = connection.Map.ToList().FirstOrDefault();
     }
 }
        /// <summary>
        /// Event: Connect to the database.
        /// </summary>
        /// <param name="sender">Sender</param>
        /// <param name="e">Event Args</param>
        override protected void btnConnected_Click(object sender, RoutedEventArgs e)
        {
            #region The code required for diagnosis - measures the time
            var spectator = new Stopwatch();
            spectator.Start();
            #endregion
            // Sample.
            lstFriends.Items.Clear();
            _listOfFriends.Clear();

            using (var mapContext = new MapContext())
            {
                IQueryable<Map> queryMap = null;

                if (txtLogin.Text == string.Empty && txtPassword.Text == string.Empty && txtId.Text == string.Empty)
                    MessageBox.Show("More than one field is not filled", "Connection error", MessageBoxButton.OK, MessageBoxImage.Error);
                else if (txtLogin.Text == string.Empty && txtPassword.Text == string.Empty && Convert.ToInt32(txtId.Text) < 500001)
                {
                    var idFromTxt = Convert.ToInt32(txtId.Text);
                    queryMap = mapContext.Map.Where(x => x.User_Id == idFromTxt);
                }
                else if (txtLogin.Text != string.Empty && txtPassword.Text != string.Empty && txtId.Text == string.Empty)
                {
                    var pass = GetMd5Hash(txtPassword.Text);
                    queryMap = mapContext.Map.Where(x => x.Login == txtLogin.Text.ToString() && x.Password == pass);
                }
                else
                    MessageBox.Show("Check the correctness of filling the fields", "Connection error", MessageBoxButton.OK, MessageBoxImage.Error);

                if (queryMap != null)
                {
                    var find = queryMap.ToList();
                    var userId = find[0].User_Id;
                    Connected(userId);
                }
            }
            #region The code required for diagnosis - measures the time
            spectator.Stop();
            var ts = spectator.Elapsed;
            lblTime.Content = $"Lead time: {ts.Hours:00}:{ts.Minutes:00}:{ts.Seconds:00}.{ts.Milliseconds/10:00}";
            #endregion
        }