Filter query

Asked

Viewed 49 times

1

To insert a filter in my query the command is in a repository and I want to insert a filter in it, it can be by name for example.

Code:

public IList < T > Consultar() {
using(ISession session = FluentnHibernateHelper.OpenSession()) {
 return (from e in session.Query < T > () select e).ToList();
}
}

1 answer

0


You can enter the filtered values in another list.

var suaListaAux = suaLista.Where(a => a.AtributoASerComparado == variavel ).ToList();

Being:

suaLista = List to be filtered
suaListaAux = List that will receive filtered value
AtributoASerComparado = Return value you want to compare
variavel = variable that receives the value that will be used in the purchase

This will filter your list to show only values that have what you want.

  • I ended up doing it a little differently, but following this line, thank you very much for the help my dear. #PEACE

  • How good, put as it solved (For if someone has the same doubt) and if possible positive if it worked my idea :).

  • I created a public method within the repository class and insert the following code. using (Isession Session = Fluentnhibernatehelper.Opensession()) { var file = Session.Queryover<File>() . Where(a => a.Primario == true); Return file.List<File>(); }

  • Nice! looks like it works

  • 1

    Yes, actually I have little experience with C# working, seeing new things like parameterization and hybernate.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.