So I am writing an application which need to select an entity at run time and add through the entity framework save this to a database, I have created the database and a model based off it through the use of an ADO.NET Entity Data model, the objects, which hold the data are chosen baised on the data that is being added at runtime with the use of the reflection class, as follows;
mytype = Type.GetType(objName);
myObject = Activator.CreateInstance(mytype);
How can I do something like this to select the entity to use, is can i do something like this:
db.[MyEntity].Add(myObject);
db.SaveChanges();
Thanks
You can get DbSet by entity type:
You can use generic Set and create a generic method.
Usage.