EntityFramework error. I really need help.

OK, so the company I work for has an owner that continues to try to be the technical lead. he refuses to allow me, Or EF to create tables, he must do it. He prefixes everything with something ridiculous. now I am at a complete loss. He made me a table the other day, I setup my Class (to match his table) and I did not realize he did not specify a primary key.

e.Message = “Unable to update the EntitySet ‘ApplicationStuffs’ because it has a DefiningQuery and no <UpdateFunction> element exists in the <ModificationFunctionMapping> element to support the current operation.”

I went back into the table and said, OH GEE, no PK. I added it and I continue to get this error. here is some code…

it fails when I save the context after adding a record. the table does have a PK, there are no FK or other relations to this table..

public class DatabaseContext : DbContext

{

public PlannerDatabaseContext(string connectionString) : base(connectionString) { }

public virtual DbSet<Presentation> Presentations { get; set; }

public virtual DbSet<AppSlide> AppSlides { get; set; }

protected override void OnModelCreating(DbModelBuilder modelBuilder)

{

//modelBuilder.Entity<AppSlide>().ToTable(“ApplicationStuffs”);

}

}

public class MobileAppDocumentConcrete : IAppDocument

{

private readonly DatabaseContext context;

public MobileAppPresentationConcrete(DatabaseContext context)

{

this.context = context;

}

public AppDocument Get(int docId, int personId, int locationId)

{

try

{

AppDocument existingAppDocument = null;

existingAppDocument = context.AppSlides

.SingleOrDefault(p => p.slidesDocID == docId

&& p.slidesPersonID == personId);

if (existingAppDocument == null)

{

var newMobileAppDocument = new AppSlide()

{

// add some data…

};

context.AppSlides.Add(newMobileAppDocument);

context.Entry(newMobileAppDocument).State = System.Data.Entity.EntityState.Modified;

context.SaveChanges(); //FAILS!

return newMobileAppDocument;

}

else

{

return existingAppDocument ;

}

}catch(Exception e)

{

var m = e.Message;

/r///e.Message = “Unable to update the EntitySet ‘ApplicationStuffs’ because it has a DefiningQuery and no //<UpdateFunction> element exists in the <ModificationFunctionMapping> element to support the current operation.”

return null;

}

}

}

submitted by /u/Eaglescout801
[link] [comments]

Leave a Reply