jeudi 26 février 2015

ASP.NET universal controller for database dictionaries (using Entity Framework)

I've got some models that only have two fields: Id and Name. All this models inherit from IDbDictionary interface.


My goal is to make "universal" controller for CRUD operations for this models. My problem is how to (using EF) modify database table by name. For example, there is method



[HttpPost]
public ActionResult Create(IDbDictionary newRecord, string collectionName)
{
if (ModelState.IsValid)
{
db.<collectionName>.Add(newRecord);
db.SaveChanges();
return View("Success");
}

return View("Create", newRecord);
}


Is there a way to do it the way I described? I thought about reflection, but I've no idea how to do this.


Regards,

C






Aucun commentaire:

Enregistrer un commentaire