I know this question has been asked a bunch of times on StackOverflow, but none of the answers seem to fit my situation, or they just tell them to allow NULL fields in their DateTime (which I don't want to do).
Here is the code:
public async Task<int> CreateJobAsync(JobViewModel jvm)
{
Job j = new Job();
j.Name = jvm.Name;
j.UserId = jvm.UserId;
j.ClassDefinition = jvm.ClassDefinition;
j.DaysToRun = jvm.DaysToRun;
j.ToEmail = jvm.ToEmail;
j.Active = true;
j.CreatedDate = DateTime.Now;
j.ModifiedDate = DateTime.Now;
context.Jobs.Add(j);
var result = await context.SaveChangesAsync();
return result;
}
All my fields in the Job
class are DateTime
as are the object in the database. The date values are not NULL
. When I run Sql Profiler, it doesn't even show that a database call was made.
The Error occurs on the await
call and it is:
conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value
This seems like a fairly easy example and I do need these values to be not null
. Any other ideas???