Want to check if there are any entries in the ClientAccessCode table if you don't return false ...
if (!CheckAccessCodeExists())
{
Console.WriteLine("Client Access code does not exist");
throw new ConfigurationErrorsException("Client Access code does not exist");
}
private static bool CheckAccessCodeExists()
{
using (EPOSEntities db = new EPOSEntities())
{
ClientAccountAccess clientAccess = db.ClientAccountAccesses
.OrderByDescending(x => x.Id)
.Take(1)
.Single();
if (clientAccess != null)
{
return true;
}
return false;
}
}
// this labeled sequence contains no elements in the lamba expression, so how can I just return false? Is some use of .Any () possible?
thank
EDIT
Thats thank you very much for helping the guys il to mark the answer now, also another request if I had
ClientAccountAccess clientAccess = db.ClientAccountAccesses
.OrderByDescending(x => x.Id)
.Take(1)
.Single();
if (clientAccess != null)
{
db.DeleteObject(clientAccess);
}
how can i reorganize this to say something neater like
if (db.ClientAccountAccesses.Any())
{
db.DeleteObject(//what does in here do I have to use above code to get record to delete?);
}
source
share