Give preference to results that have the parameter passed in the Entity Framework

Asked

Viewed 41 times

1

I am trying to implement a data solution that displays first the values that have the parameter passed to then pass the other parameters.

Example:

In a product table has the following data:

Coca-Cola  -> Coca Cola Company
Pepsi      -> Pepsico
Toddy      -> Pepsico
Dolly      -> Dolly
Itubaina   -> Schin

When I pass the parameter the manufacturer "Pepsico" in the Entity Framework it should display the values in the following order:

Pepsi      -> Pepsico
Toddy      -> Pepsico
Coca-Cola  -> Coca Cola Company
Dolly      -> Dolly
Itubaina   -> Schin

How can I do this?

  • What have you ever tried to do?

  • Perform two searches, one to take the data of the parameter and the other for the other data, but wanted something more efficient

  • Yeah, but like this?

  • var lista = Products.Where(x=> x.Manufacturer == "Pepsico"). toList(); var listSemParametros = Products.Where(x=> x.Manufacturer != "Pepsico"). toList(); after this I join the two lists

  • @Gustave occurences, there are two types of ordination, by ancestry and descent. Why do you want to make this ordination ? By chance "Pepsico" is the best selling product ?

  • is just an example of parameter the user passes

Show 1 more comment

1 answer

2


You can do it that way:

var result = Produtos.OrderByDescending(e => e.Fabricante.Contains("Pepsico"));

Browser other questions tagged

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