(I've put "...to Entities" in brackets since I don't know if this matters at all. I guess this is a quite general LINQ related question.)
I want to check with LINQ (to Entities) if an object exists in the database. At the moment I am doing the following:
using (MyEntitiesContext aCtx = new MyEntitiesContext())
{
var aQuery = from c
in aCtx.Client
where c.ClientID==1
select c;
Client aClient = aQuery.FirstOrDefault();
bool Exists = (aClient!=null);
...
}
But (if I am not wrong) this loads the full Client object from the database (if the Client exists). I am actually only interested whether it exists or not without loading the object.
SQL has the SELECT COUNT(*)...
construct. Is there something similar I can do with LINQ?
Thank you for advice!