0

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. Entity Framework C# queries from strings


this is the UI 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;
}
7
  • The question is unclear. EF deals with application entities not tables. It's an ORM, not a data access library, that's what ADO.NET is for. Commented Jul 26, 2022 at 8:22
  • As for the answer you link to, it's an expensive and barely functional answer to a very bad question. That's simply not what ORMs are for. That's why so much code is needed to generate SELECT ID from MyTable. That's like trying to drive a nail with an electrician's scredriver. Sure, it's possible Commented Jul 26, 2022 at 8:24
  • @PanagiotisKanavos thanks for your answer. i know ntt framework it's not ideal to do this but i'm new in the db world and it's the only thing i used to deal with dbs, so, the web app i'm creating uses only ntt framework. could you please help me out in some way? Commented Jul 26, 2022 at 8:29
  • You didn't ask a question yet. Either you don't need strings or don't need an ORM for whatever it is you want to do. What is the actual problem you want to solve? You only described what you think the solution would look like Commented Jul 26, 2022 at 8:33
  • I do not understand question. A way a lot of more details are needed. At least sample. Commented Jul 26, 2022 at 8:37

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

5 Comments

yes, i'm using MVC.I've got many entity and my tables in my db and i'm trying to create only one function that can be used with every entity without writing a huge switch case which is not reliable at all. For the GET function, it was a mistake, now i fix it
FYI: POST is fine too for delete operations. I got your point but my thought is that by trying to make only one function for every entity ruins the "nature" of MVC. Being based on controllers and views, it actually is good practice for each entity to have its own controller
The fact is that this Web App will probably be updated in time so I'd like it to be the most "ready-to-go" possible and doing this would make it easier to use later and with less lines of code. (I'm still in High School and I'm still learning so any suggestion is much appreciated)
Got your point again, but as a 23yo graduated just two and a half years ago I recommend you to learn the basic way first. When you mastered it you can do whatever you want to improve your code or optimise your applications
ok, thank you. I'll create all the new entities controllers. I mean, grazie!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.