(I put "... essentially" in brackets, because I don’t know if this matters at all. I think this is a pretty general LINQ 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'm not mistaken), it loads the entire Client object from the database (if the Client exists). I'm really curious if this exists or not without loading the object.
SQL has a construct SELECT COUNT(*).... Is there something similar that I can do with LINQ?
Thanks for the advice!
source
share