Users Pricing

forum

Home Forums how to return false if no records exist in table – MindStick

how to return false if no records exist in table

Anonymous User 2000 05 Dec 2014

Want to check if any records exist in ClientAccessCode table, if not 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 is flagging sequence contains no elements, in the lamba expression, so how can I just return false then? some use of .Any() perhaps?

 

Thanks


2 Answers

Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md