I’m using LINQ to Entities and I want to know how do I translate the following query to lambda expression using extension methods.
public _Deposito RegresaDepositosBancarios(int id)
{
return (from d in context.depositos_bancarios
where d.IDDeposito == id
select new _Deposito
{
idDeposito = d.IDDeposito,
cantidad = d.Monto,
fecha = d.FechaDeposito,
aplicado = d.Aplicado
}).Single();
}
Notice that I’m returning a _Deposito type, how do I achieve this using extension methods?
I need something like the following:
public Persona RegresaPersonaPorNombres(string nombres, string apellidoP, string apellidoM)
{
var p = context.personas.Where(x => x.Nombres == nombres &&
x.ApellidoP == apellidoP &&
x.ApellidoM == apellidoM).FirstOrDefault();
return p;
}
I don’t want to return an entity type but a custom type instead
This is how this would be written with extension methods, but you really should not need to worry as they are both the same thing.
An interesting side note: I could have used a
d=>in theWhereand then ane=>in theSelect. Whereas, the d propogates down throughout the phrase. The only way to reset it would be to use a let phrase. This has nothing to do with the direct question, but I just thought it interesting and wanted to point it out 🙂