Home > Back-end >  Entity Framework C# queries from string parameters
Entity Framework C# queries from string parameters

Time:07-28

I'm creating a web app based on a database. The datas in the database need to be displayed, edited and deleted by the web app user. Right now I need to remove elements in my sqlite database table after the user inputs the name of the database table and the id (which is also the primary key) of the element. How can I do it?

I always used Entity Framework before and also in the Web App so I was looking for a solution with it, but if there's a simpler way to do it, I'll stick with it.

Thank you


I think the answer here is similar but I need help to adapt it to what I need now. UI

and here is the endpoint in the backend

//DELETE method
[HttpDelete("DeleteElementInTable")]
public IActionResult DeleteElementInTable(string tableName, string elementKey) //url query parameters
{
    var db = new MyContext();
    //code to remove the item ... something like:
    DbManager.RemoveElement(tableName, elementKey); //DbManager is the static class dealing with the db context
    return //csv of the deleted element;
}

CodePudding user response:

I'm still a young developer but here I can see there are some lacks of knowledge. First of all, which technology are you using to build your web-app? From what you posted my guess is you are trying to use MVC. As @Panagiotis Kanavos said above you need an entity to interact with the database if you want to use Entity Framework, through which you don't need to pass table name in your GET function. Last but not less important you can't execute the delete operation in a GET function.

  • Related