Hi,
I'm trying to save objects to a database using EF6 with a generic method.
The method looks like this:
private void SaveDBChanges<T>(T entity) where T : class
{
using (var context = new DataContextProduction())
{
context.Set<T>().Add(entity);
context.SaveChanges();
}
}
And the call to the method looks like this:
object myObject = new DatabaseItemObject();
SaveDBChanges(myObject);
When the context.Set<> command is executed the following message appear: "The entity type Object is not part of the model for the current context"
Is there any good way to save objects like this using EF or do the objects need to be casted to the correct type before they are saved?