I am performing a query to a database and retrieve some records, I am performing a real-time search through a textbox and it works correctly. When I retrieve the data I save it in a list and on it I perform the filter with Linq as follows:
Here I load the data from the DB to a list:
private List<MConductor> conductores;
conductores = VmConductores.BuscaConductores();
and in this way I try to perform the search in said list on the data already loaded:
GridConductores.ItemsSource = conductores.Select(
c => new
{
c.IdConductor,
c.Nombre,
c.ApellidoPaterno,
c.ApellidoMaterno,
c.Licencia,
c.LetraLicencia
}).
Where(c => c.Nombre.Contains(txtBusquedaConductores.Text)
|| c.ApellidoMaterno.Contains(txtBusquedaConductores.Text)
|| c.ApellidoPaterno.Contains(txtBusquedaConductores.Text)
);
All this works but, when I want to use them as MConductor type, it tells me that it cannot be converted from Anonymous type to MConductor
How could I convert that anonymous object to the type of my MConductor model?
Attached image of where the IEnumerable error marks me when I want to convert it into an MConductor model:
Instead of an anonymous object create an object of type MConductor and assign the properties to it: