All was working fine until I added a new column to my table. I could not find how to update the model class, so I added the column myself in model. But now, when I run my application, I get error: "Object reference not set to an instance of an object."
During debug, I found that it is the problem with creation of instance of my dbcontext:
MyDbContext context = new MyDbContext(db);
The context object is Not fetching rows from table and is giving this Object reference error.
If I remove the new column from Model class then it works fine. That suggests that my database and model is Not in sync and it seems that the application is using old table design.
I am also trying to use CLI commands to update database but facing difficulties in that as well.
Can anyone suggest how to make model class and table design in sync once a table column is added? I am using ASP.NET Core and EF Core.
put try catch to find the exact problem.
This problem occurs because of the difference between schema of database and changed schema at code level. you need to add this line.
It will synchronize your database.