Problems adding an object to the database in the Entity Framework

I have the following code trying to add an object to a database:

public static void saveAudit(List<AUDIT> audit)
{
 Entities dao = new Entities();

 foreach (CMUAUDIT a in audit)
 {
    dao.CMUAUDITs.AddObject(a);
 }

 dao.SaveChanges();
}

However, I get an error message:

"... does not contain a definition for AddObject and an extension, the AddObject method, which takes the first argument of the type" System.Data.Entity.DbSet ", can be found (do you miss the using directive or assembly references?)"

I did some searches, and there is a mention that the primary key has something to do with it. Any suggestions?

Am I using a DB2 database if that makes any difference?

+3
source share
1 answer

...System.Data.Entity.DbSet...: -, Entities DbContext, ObjectContext. CMUAUDITs DbSet<T> ( a ObjectSet<T>). DbSet<T>:

dao.CMUAUDITs.Add(a);

AddObject ObjectSet<T>.

+6

All Articles