kagushajeiel
kagushajeiel

Reputation: 81

Unable to retrieve metadata for my model, NullReferenceException

Error Message

I have been trying to fix my error for 2 hours but every attempt comes to no avail. What I've been trying to do is follow this MVC tutorial step 4-6.

1.) What I did is I created a model with this code:

using System;
using System.Data.Entity;
using System.Web.UI.WebControls;

namespace Bakunawa.Models
{
    public class BakunawaModels
    {
    public int ID { get; set; }
    public string Title { get; set; }
    public DateTime ReleaseDate { get; set; }
    public TextBox Memo { get; set; }
    }

    public class BakunawaDBContext : DbContext
    {
    public DbSet<BakunawaModels> Notes { get; set; }
    }
}

2.) Then added my connection string in the Web.Config file:

    <add name="BakunawaDBContext"connectionString="Data Source (LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Notes.mdf;Integrated Security=True" providerName="System.Data.SqlServerCe.4.0" />

3.) Finally, I tried to add my controller (scaffolding) like this:

3rd step

However, as shown above, the program states an error message.
Unable to retrieve metadata for 'BakunawaModels.BakunawaModels'. Object reference not set to an instance of an object.

Troubleshooting steps I did was:
1. Build, Rebuild, and Clean the program.
2. Restart the computer.
3. I checked google for relevant answers, to no avail. My google search
4. I checked stack overflow for this as well, similar questions popped up and I tried stuff like:
a. changing the connection string to "System.Data.SqlClient"
b. my search for stack overflow: My stackoverflow search
5. I created another program and followed the tutorial word-for-word, and it works so I know something is wrong with my code. Kindly enlighten me.

Upvotes: 1

Views: 394

Answers (1)

Glenn Ferrie
Glenn Ferrie

Reputation: 10400

You cannot have a WebControl in your model. You should change Memo from a TextBox to a string

Upvotes: 1

Related Questions