Error ASP.NET Core EF Core and SQL Server 2005: The version of SQL Server in use does not support datatype 'datetime2'

asp.net-core-mvc entity-framework entity-framework-6 sql-server-2005

Question

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?

Controllers/SecureController/Save

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");
}

ViewModels/SubscriptionsViewModel.cs

 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); }
            }
        }
    }

Models/Subscription.cs

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; }
    }
}
1
2
9/15/2016 8:19:18 AM

Accepted Answer

EF Core does not support SQL Server 2005, but 2012 and forward

https://docs.microsoft.com/en-us/ef/core/providers/sql-server/

7
11/22/2019 9:01:44 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow