I'm new to using SQL Server 2012 and the Date type in my C# applications and am curious about the conversion to DateTime. I have a DBML file representing my table and a type that has a server data type of Date and a type of DateTime. I'm trying to do a simple comparison between the current day and the value in my table:
if (adc.HolidaySchedules.FirstOrDefault(d => ((DateTime)d.HolidayDate).Date.AddDays(-1) == DateTime.Today.Date) != null)
It throws the following SqlException
The datepart millisecond is not supported by date function dateadd for data type date.
I'm curious as to why I'm getting this particular exception when I'm only accessing the Date and what I should be doing, explicitly or otherwise, to handle this type of conversion. I would have thought I could call AddDays() on a Date.
SqlMethods.DateDiffYear(o.ModifiedDate, DateTime.Now) > 1