I'm using Entity framework to manipulate a data base, and I was wondering if I could used a variable to call a method
I tried with this way:
string name = "tableName";
db.[name].AddRange(dates.[name]);
but it didn't work
I want to call a method of this way because I'm going to do multiples inserts in different tables. and I have in mind use an array or some collection with all the names of the tables.
and then iterate the collection
public ActionResult MetodoRecibe(Reporte datas)
{
string name = "tableName";
db.tableName.AddRange(datos.tableName);
db.SaveChanges();
return Json(datas, JsonRequestBehavior.AllowGet);
}
My variable data is Json with the following structure:
datas{
nameTable1[],
nameTable2[],
nameTable3[],
.
.
.
.
nameTable13
}
I had considered using a switch case
as a last resort but because of the quantity of tables I would prefer to use the first option.