I want to perform a generic insert in entity framework. This is what I wrote -
static public void Insert<T>(MyEntities DataContext, T obj) where T : class
{
try
{
DataContext.AddObject(DataContext,obj);
DataContext.SaveChanges();
}
catch (Exception e)
{
throw new Exception("Problems adding object" + e);
}
}
But as you can see the AddObject method is not what i want...it gives exception as it expects an enitysetname I want to pass in the object and then add that object to my database. But I cannot do AddtoObjectName() as I dont know the object. Can anyone point me in the right direction here..