public IEnumerable <Chat> GetUserChats(Guid userid) { if (!UserExists(userid)) { var resp = new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent($"Пользователь с ID = {userid} не найден"), ReasonPhrase = "User ID Not Found" }; throw new HttpResponseException(resp); } using (var connection = new SqlConnection(_connectionString)) { connection.Open(); using (var command = connection.CreateCommand()) { command.CommandText = "SELECT * FROM ChatUsers WHERE UserId = @id"; command.Parameters.AddWithValue("@id", userid); using (var reader = command.ExecuteReader()) { while (reader.Read()) { yield return(_chatReposirory.Get(reader.GetGuid(reader.GetOrdinal("ChatId")))); } } } } }