views:

990

answers:

1

I have an ASP.NET MVC application where I am editing an existing database to update a paticular field, DateTime. My database has 4 fields, two of which are DateCreated and DateModified. When I try to update the field, I want to keep DateCreated time the same, no reason to update the date it was created, and I change the DateModified time to the current time using DateTime.Now

Here is the given code just in-case I am doing something wrong. This is my first time using ASP.NET MVC so go gentle. I have seen other answers where Context is called, but I can't find any reference to it. When I run the application I receive the error message in the title and the contractEntity.SaveChanges() is in red.

        public ActionResult Edit(Contract editContract) {
        var contract = (from c in contractEntity.Contracts where c.Id == editContract.Id select c).First();
        if (!ModelState.IsValid)
            return View(contract);
     // editContract.DateCreated = contract.DateCreated;
     // editContract.DateModified = DateTime.Now;
        contractEntity.ApplyCurrentValues(contract.EntityKey.EntitySetName, editContract);
        contractEntity.SaveChanges();
        return RedirectToAction("Index");
    }

Please, any help is appreciated. Thanks.

+1  A: 

After reading a website I found to open the .edmx file for my database and change:

<...Provider="System.Data.SqlClient" ProviderManifestToken="2008".../>

to

<...Provider="System.Data.SqlClient" ProviderManifestToken="2005".../>

Is this acceptable or is there a better approach to fixing that error?

Anthony Forloney
What website?...
Robert Harvey
http://ifunky.net/post/Type-datetime2-is-not-a-defined-system-type-Entity-Framework.aspxSorry, would have helped if I had posted.
Anthony Forloney
This change stops the EF from using DATETIME2 type at all. Is that the correct solution for your app? Only you can say that. If you intend to use DATETIME2, plan around that.
Craig Stuntz
This is the correct solution for my particular app, but do you know of a way around it? I do not know why the error occured since the field i was changing was DateTime not DateTime2
Anthony Forloney