Reputation: 83
I'm getting error CS1061 on my ASP.NET web app.
'Entities' does not contain a definition for 'AspNetRoles' and no extension method 'AspNetRoles' accepting a first argument of type 'Entities' could be found (are you missing a using directive or an assembly reference?)
There are over 90 CS1061 error messages for all tables and actions (add, change, delete,get, etc), like below:
using EntityData.Model;
using EntityData.Modules;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EntityData.Actions
{
public class AspNetRolesActions : BaseActions<AspNetRole>
{
public override void Add(AspNetRole t, Guid by)
{
ctx.AspNetRoles.Add(t);
Save();
}
Web app was working fine until I updated the data model to reflect the changes I made on the SQL DB. I tried cleaning and rebuilding to no avail.
If I revert the changes to the data model, I can run the app without a problem.. but then I cannot save data on the new field I created..
What could be happening?
Upvotes: 3
Views: 5097
Reputation: 83
Thanks to Daniel for giving me an idea how to solve this issue.
When Visual Studio's Update Wizard re-created the data model, it used a different class name than what is already in my app.
So what I did was to modify the generated DataModel.context.cs to use the previous name, and all errors are now gone..
I repeated this process a couple of time to confirm this is the solution.
Couldn't have solved this without Daniel's help.. Thanks!
Upvotes: 1
Reputation: 15778
Most probably when you change the SQL Table schema, your app was not able to find exactly the mapped table to the context. In other words: it lost the sync with the SQL Db.
If you're using "EF DbContext Generator" you must open the '.tt' file and re add the table.
Is important to you know that the tables in your context generator DOES NOT reflect exactaly you database scheme. In any case you must re-map your context to your DB Scheme.
Take a look at the .tt file that you should have in your solution.
Verify if the modified table exists in the context with the new column.
If it does not, the easy way is to remove the table and re add it from the db.
Then rebuild your solution.
Upvotes: 2