I am using the following code:
public class BtnCountViews
{
public int btnCount { get; set; }
public int views { get; set; }
}
var btns = "(BTNACOUNT + BTNBCOUNT) AS BtnCount, VIEWS As Views";
Counts.btnCountViewsToday =
db2.Query<BtnCountViews>("SELECT " + btns + " FROM CLICKHISTORY WHERE YYMMDD = " + yymmdd).First();
When there is no record returned for the day yymmdd then this errors out with a message saying sequence contains no elements
.
I do understand why this is happening but would like some suggestions on how I could stop it throwing an exception.
What I would like to do if there are no elements is for Counts.btnCountViewsToday to contain an object populated with a 0 in the btnCount and the views fields.