I created a sample project using entity framework 4. It was fairly simple, I created a new data model by choosing EF Designer from database. Created the data connection and selected all tables from my database. It seems fine - I am able to see the tables in the designer.
The problem is that then I can't add or delete objects. My db class looks like that:
namespace DBAccess
{
public class DatabaseAccess : IDisposable
{
private MyDBModel dbModel;
public DatabaseAccess ()
{
dbModel= new MyDBModel();
}
public Accounts AddAccount()
{
var A = new Accounts();
dbModel.Accounts.AddObject(a); // here's the "Cannot resolve symbol 'AddObject'" error
}
public void DeleteAccount(Accounts a)
{
dbModel.DeleteObject(a); // here's the "Cannot resolve symbol 'DeleteObject'" error
}
}
}
Why can't I use these methods? I've used them before in other projects..
This is the connection string in the App.config
file:
<connectionStrings>
<add name="MyDBModel" connectionString="metadata=res://*/MyDBModel.csdl|res://*/MyDBModel.ssdl|res://*/MyDBModel.msl;provider=System.Data.SqlClient;provider connection string="data source=MyServer;initial catalog=MyDB;persist security info=True;user id=MyUser;password=MyPassword;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
Okay, I found a solution, although I'm not sure if it's the right one..
I found this article on Microsoft's website http://msdn.microsoft.com/en-us/data/jj556581.aspx
The settings on my data model were different. In Code Generation Strategy
I have T4
and Legacy ObjectContext
. It was set to T4
and I changed it to Legacy ObjectContext
. Then under the .edmx
file I delete the two files with .tt
extensions. In my case they were MyDBModel.Context.tt
and MyDBModel.tt
.
Rebuilt the whole solution and it works now.
I hope it will help to someone.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.