I have a query made using linq to SQL which result will be shown in a datagridview with sorting and filtering options.
public IQueryable RegresaDepositosBancarios()
{
var depositos = from d in context.depositos_bancarios
where d.Aplicado == false
orderby d.FechaDeposito ascending
select new
{
d.IDDeposito,
d.cuentas_bancarias.Nombre,
d.Monto,
d.FechaDeposito,
d.Observaciones
};
return depositos ;
}
Later in my code I set the datasource to use previous result.
var depositos = operaciones.RegresaDepositosBancarios();
dataGrid_depositos.DataSource = depositos;
As you can see I’m returning and IQueryable of anonymous type and I can’t perform sorting or filtering over this. I read that you can implement a custom function to convert IQueryable to DataView and then use the RowFilter property, is this the more efficient way of doing it? Could be better to return other type in my function?
Any suggestions are welcome
You should change the return type from
IQueryabletoIEnumerable<dynamic>, then you can do something like:I think you could also code it this way (however I don’t normally use
fromso am not sure)Here’s a test program.