For a school work I'm trying to develop a kind of search on my News SQL table.

I get from a text box the search query (split by ;) and then I query the database comparing the user query in lowercase with the titulo, the descrição and the tags in lowercase. This runs fine until the second foreach, I'm not having success merging a list of IOrderedQueryables.

  String[] terms = TrabPratico1.Funcoes.splitString(tbTermos.Text, ';');
    List<IOrderedQueryable<Noticias>> listaResultados = new List<IOrderedQueryable<Noticias>>();
    foreach (String term in terms)
        listaResultados.Add((from noticia in bent.Noticias where noticia.Titulo.ToLower().Equals(term.ToLower()) || noticia.Descricao.ToLower().Equals(term.ToLower()) || noticia.Tags.ToLower().Equals(term.ToLower()) select noticia).OrderByDescending(x => x.Data));
    var resultado = Enumerable.Empty<Noticias>().AsQueryable<Noticias>();
    foreach (IOrderedQueryable<Noticias> iq in listaResultados)
    //lblResultados.Text = resultado.Count().ToString();
    lvResultados.DataSource = resultado;

The bent variable is an Entity Framework class.

My code runs fine (does return the appropriate number of news) but I've been trying to join the list of IOrderedQueryable in order to put it on a ListView, however it always throws an exception that lvResultados must have a data source which implements ICollection or that proceeds to data source paging if AllowPaging is true (sorry roughly translated from Portuguese).

I'm doing concat inside of the second foreach, but I feel that it should be Union to remove duplicates.

Related posts

Recent Viewed