I'm new with LINQ. I'm using this function:
public IEnumerable<Vendedores> GetVendedores()
{
using (var context = new OhmioEntities())
{
Vendedores _allvendors= new Vendedores();
_allvendors.Nombre = "All Vendors";
_allvendors.ID_Vendedor = -1;
var query = context.Vendedores;
var _vendors= query.Where(f => f.Activo == true).OrderBy(o=>Nombre).ToList();
_vendors.Insert(0, _allvendors);
return _vendors;
}
}
It should give me order list of active vendors. The where part work fine, but the order is ignored and the records after the .ToList are in the original table order. What i'm i doing wrong? Thank you!
I think you need o.Nombre
instead of Nombre
var _vendors = query
.Where(f => f.Activo)
.OrderBy(o=> o.Nombre)
.ToList();
Also f => f.Activo == true
can be written as f => f.Activo
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With