how to return the following query from a model using entity framework (I'm a beginner in this framework):
var datos = (from x in db.ReporteOperativo select new { x.REFERENCIA,x.DESCRIPCIONMATERIAL, x.ADUANAENTRADA,x.NOMBREBUQUE, x.IMPORTADOREXPORTADOR, x.PARQUEEOLICO, x.REGIMENOPERACION, x.HBL, x.TIPOCONTENEDOR, x.NUMEROCONTENEDOR, x.ETD, x.ETA,x.ATA,x.FACTURACOMERCIAL, x.PO, x.NCR, x.ACCODE,x.VALORMERFACTURA, x.FLETE, x.SEGUROINCREMENTAL, x.OTROSINCREMENTABLE, x.TOTALVALORFACTURA, x.TIPOCAMBIO, x.VALORADUANAMN, x.DTAMN, x.PARTESII, x.IGIMN, x.IEPS, x.IVAMN, x.MULTAS, x.RECARGOS, x.REVALIDACION, x.TOTALEFECTIVOMN, x.FECHAPAGO,x.FECHAVENCIMIENTO,x.SECCIONADUANA, x.FECHADESADUANAMIENTO, x.SELALEATORIA, x.FECHAENTREGA, x.ALMACENAJE, x.DESCONSOLIDACION, x.PARTIDASSINIVA, x.MANIOBRAS, x.FLETELOCAL, x.TOTALLOCAL, x.HONORARIOS, x.TOTALOPERACION, x.TOTALLSP, x.EXCHANGERATE, x.AMOUNTUSD, x.RESPONSABLE, x.Status.STATUSAA}).ToList();
it only allows it to be done but from the controller, I want to do all kinds of queries in the model, however I have the problem to return them as a list, it is a oneToMany relationship. (Attached the img of the error that I constantly get or how could it be a query that can be returned to paint a gridView to export it to excel with a oneToMany relationship)
try this
In your models folder you could add a class that contains the attributes you require
and already in your query you can indicate that it returns
OperativoConstruccion
and not the complete class that you are defining, the query would be something like this:or if what you want is to return all the values, simply make the query like this: