尝试更新数据库记录时收到以下异常,即使我将正确的日期时间值传递给控制器.
System.ArgumentException:正在使用的SQL Server版本不支持数据类型'datetime2'
其他stackoverflow主题建议尚未设置日期时间或编辑edmx文件,在这种情况下,该文件不存在.我已经在Visual Studio 2015中使用localdb上下文测试了该应用程序,但我在尝试连接到SQL Server 2005 DbContext时只收到错误.
这是因为与SQL Server 2005不兼容导致的异常还是我缺少一种解决方法?
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");
}
Run Code Online (Sandbox Code Playgroud)
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 …Run Code Online (Sandbox Code Playgroud) entity-framework sql-server-2005 entity-framework-6 asp.net-core-mvc