0

I have a working website (designed in MVC), along with a database on the host site, that I'm connected to via a connection string provided by the host.

The site was working probably ; yet I needed to update the code, and with it update the only model I have : which contains representations of 3 tables (my modification yet to make it represent four).

I only add classes, with the physical table's name (without the extra s).

I migrated a new table to the server, but whenever I define a new model to represent that table, all my views and controllers, which contain model initialization simply don't work and redirect me to a small error page I made.

Could somebody guide me to what the problem might be ?

public class xModel
{

    public class a
    {
        public int Id { get; set; }
        public string Title { get; set; }
        public string Desc { get; set; }
        public string source { get; set; }


    }
    public class b
    {
        public int Id { get; set; }
        public string name { get; set; }
    }
    public class c
    {
        public int Id { get; set; }
        public string name { get; set; }
        public string des { get; set; }
        public string author { get; set; }

    }
   public class d
    {
        public int Id { get; set; }
        public string Country { get; set; }
        public string Street { get; set; }
        public double x { get; set; }
        public double y { get; set; }
    }
}
public class DatabaseConnection : DbContext
{
    public DbSet<xmodel.a> a { get; set; }
    public DbSet<xmodel.b> b { get; set; }
    public DbSet<xmodel.c> c { get; set; }
    public DbSet<xmodel.d> d { get; set; }
5
  • What you ask is not clear. You need to specify what error you got. If you can't understand what error you got, you may debug and see where it is happening. Or you can turn off the custom error page from web.config by putting your CustomErrors="Off" and try to run the program. Then you can see the error in the page Commented Apr 4, 2015 at 9:18
  • @jubair the error originates from the last line in the code I posted : public DbSet<xmodel.d> d { get; set; }, whenever this connection is gone the code works (I explained that above). The table is on the server (I double checked), asp.net treats the line as if the table doesn't exist. Commented Apr 4, 2015 at 9:31
  • Have you created the table using migration from nuget package manager console? In your statement, you told you migrated a table and then created the model. My guess is you didn't use .net migration. right? Commented Apr 4, 2015 at 9:45
  • @jubair no I didn't ; I used "sql server import & export wizard" ; I didn't migrate it from within visual studio Commented Apr 4, 2015 at 10:02
  • Note : I have read your answers, all commentators & I'm thankful ; I shall practice each solution and see what I might find. I tried to catch the error in a small try/catch covering the initilization statement of a variable containing the child "DbContext" ; though nothing was catched (using Exception ; printing its message". I'll keep tracing and report back if I found the answer. Commented Apr 4, 2015 at 16:13

2 Answers 2

1

This problem may occur because you import and export it and didn't use .net migration. I dont know the exact reason but I faced it several times. One way to solve the problem if you generate the entities(model) directly from the server. You can use the Ado.net entity data model to automatically generate your entities from databae.

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

1 Comment

Thank you so much @jubair ; it's a migration problem as you said, I changed my server's stored "web.config" to allow error reporting, then it compiled it to a migration issue, including this link : msdn.microsoft.com/en-us/data/jj591621 ============I actually stopped early at the solution (only updating the models, since the database was already there from my previous migration).
0

Build the application before going on to the next step.

Right-click the Controllers folder and create a new MoviesController controller. The options below will not appear until you build your application. Select the following options:

Controller name: MoviesController. (This is the default. )
Template: MVC Controller with read/write actions and views, using Entity Framework.
Model class: Movie (MvcMovie.Models).
Data context class: MovieDBContext (MvcMovie.Models).
Views: Razor (CSHTML). (The default.)

Read More

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.