Aufa Husen
Aufa Husen

Reputation: 133

ASP.NET MVC System.Data.Entity.Core.EntityCommandExecutionException

I'm having an issue in Asp.net MVC, I have tried several suggestions and looking over Stack Overflow with no luck.

Here are the codes and details:

Exception :

An exception of type 'System.Data.Entity.Core.EntityCommandExecutionException' occurred in EntityFramework.SqlServer.dll but was not handled in user code

Code:

Controller where it got exception:

    namespace DataCrowds.Controllers
{
    public class MarketplaceController : Controller
    {
        private ApplicationDbContext db = new ApplicationDbContext();

        // GET: Marketplace
        public ActionResult Index()
        { 
            return View();
        }

        public PartialViewResult _SearchDataSets(string keyword)
        {
            System.Threading.Thread.Sleep(2000);
            var data = db.DataSets.Where(f =>
            f.title.Contains(keyword)).ToList();
            return PartialView(data);
        }
    }
}

Inner Exception :

Class=16 ErrorCode=-2146232060 HResult=-2146232060 LineNumber=5 Message=Invalid column name 'ApplicationUser_Id'.

More Details (Image Screenshot)

Code first model:

namespace DataCrowds.Models 
{ 
    public class DataSet 
    { 
        public int Id { get; set; } 
        public string title { get; set; } 
        public string description { get; set; } 
        [NotMapped] 
        public HttpPostedFileBase file { get; set; } 
    } 
}

And yes, I have tried to run migration and update-database. Thx!

Upvotes: 1

Views: 1131

Answers (3)

Cen
Cen

Reputation: 19

Try to delete the corresponding table and rerun the migration

Upvotes: 0

Aufa Husen
Aufa Husen

Reputation: 133

i want to give some updates regarding the problem.

The Solution is for me, as @Christiaan Molendijk said in his comment.

Sorry was allready given a answer that is not really the problem. Oké so sometimes there are all ready tables that contains data. Because it already has data it cannot change the table. Then it doesn´t execute the migration. Most easy way to fixes this is to remove the tables and execute the migration. But your data will be lost then. There are other ways, you can read about that here: msdn.microsoft.com/en-us/data/dn579398.aspx – Christiaan Molendijk 3 mins ago

After deleting the tables and re run migration is all fixed!

Thx!

Upvotes: 0

C. Molendijk
C. Molendijk

Reputation: 2834

Update you database to match your Entity Framework model. That will fix this error.

Upvotes: 1

Related Questions