I receive the following exception when attempting to update a database record even though I was passing in the correct datetime values to the controller.
System.ArgumentException: The version of SQL Server in use does not support datatype 'datetime2'
Other stackoverflow topics suggest either the datetime has not been set or to edit the edmx file, which in this case, doesn't exist. I have tested the application with a localdb context in Visual Studio 2015 but I only receive an error when trying to connect to the SQL Server 2005 DbContext.
Is this exception due to an incompatibility with SQL Server 2005 or is there a workaround which I'm missing?
public ActionResult save([FromForm]SubscriptionsViewModel newSubscription)
{
if (ModelState.IsValid)
{
var mySubscription = Mapper.Map<Subscription>(newSubscription);
_context.Entry(mySubscription).State = EntityState.Modified;
_context.SaveChanges();
_logger.LogInformation("saving to database");
return RedirectToAction("subscription", "secure");
}
return RedirectToAction("index", "secure");
}
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace XX.ViewModels
{
public class SubscriptionsViewModel
{
public int SubscriptionRef { get; set; }
public int MemberID { get; set; }
public string SubTypeID { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public byte PrimaryPaysInd { get; set; }
[NotMapped]
[StringLength(15, MinimumLength = 4)]
public string searchParam { get; set; }
public SubscriptionsViewModel()
{
}
[NotMapped]
public bool PrimaryPaysIndBool
{
get { return PrimaryPaysInd > 0; }
set { PrimaryPaysInd = value ? Convert.ToByte(1) : Convert.ToByte(0); }
}
}
}
using System;
using System.ComponentModel.DataAnnotations;
namespace XX.Models
{
public class Subscription
{
[Key]
public int SubscriptionRef { get; set; }
public int MemberID { get; set; }
public string SubTypeID { get; set; }
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public byte PrimaryPaysInd { get; set; }
}
}
EF Core does not support SQL Server 2005, but 2012 and forward
https://learn.microsoft.com/en-us/ef/core/providers/sql-server/