forum

Home / DeveloperSection / Forums / how to return false if no records exist in table

how to return false if no records exist in table

Anonymous User 1706 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


Updated on 05-Dec-2014
I am a content writter !

Can you answer this question?


Answer

2 Answers

Liked By