1

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!

0

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

4 Comments

How? - I have tried running migration and update-database several times with no lucks, i would really appreciate more details. Sorry, first time developing MVC in asp.net. Thx!
Do you get messages when running migrations and/or update-database?
well it does says that there are some tables that already existed, is that a problem ? @Christiaan
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
0

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!

Comments

0

Try to delete the corresponding table and rerun the migration

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.