Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

EF Core - select MAX with subquery

$
0
0

Hello,

I'm trying to "translate" in EF core this SQL query:

SELECT * FROM Estrazioni
WHERE Estrazioni.DataEstrazione = (SELECT MAX(maxEstrazione.DataEstrazione) FROM Estrazioni AS maxEstrazione)

I have tried to write this, copying from internet, but I receive a lot of error that I don't understand:

var ultimaEstrazione = await _context.Estrazioni
             .Where(e => e.DataEstrazione == Convert.ToDateTime(_context.Estrazioni.Where(w => w.DataEstrazione == e.DataEstrazione).MaxAsync(w => w.DataEstrazione)))
            .Select(e => new { e.DataEstrazione, e.Estrazione01 });

Could someone please help me to write the right code?

Thank you


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>