0

I have a single purpose website which processes a web-hook and stuffs a parameter into a database.

In other words, no need for the full entity framework.

So what is the simplest possible way to do this?

The entire website is currently written in about 10 lines of code, and I would like to keep it as simple as possible. In other words, I don't want to write the Context and Model. Just a simple insert statement would work for me.

app.Run(async (context) =>
      {
        string body;
        using (StreamReader stream = new StreamReader(context.Request.Body))
        {
          body = stream.ReadToEnd();
          //body = id=12345;
        }


        if (!String.IsNullOrWhiteSpace(body))
        {
          var id = StringToDictionary(body).FirstOrDefault(a => a.Key == "Id").Value;

          //Stuff ID in a table.

        }
        await context.Response.WriteAsync("Hello World!");
      });
    }
Greg Gum
  • 33,478
  • 39
  • 162
  • 233
  • 1
    I guess you'll need to elaborate on what you mean by "simplest." Entity Framework will have an extra dependency, but it'll be the easiest to write and maintain, the fewest lines of code, and the easiest to scale up if necessary. – Strikegently Sep 24 '18 at 18:07
  • @Strikegently, I clarified a bit above. – Greg Gum Sep 24 '18 at 18:11
  • Possible duplicate of [How can I add user-supplied input to an SQL statement?](https://stackoverflow.com/questions/35163361/how-can-i-add-user-supplied-input-to-an-sql-statement). The suggested duplicate would be my vote as answer (using ado.net) but the question is rather subjective. – Igor Sep 24 '18 at 18:14
  • @Greg0 ADO.NET would achieve that. It's essentially a step down in the abstraction layer from EF. https://stackoverflow.com/questions/40506382/what-is-the-difference-between-an-orm-and-ado-net – Strikegently Sep 24 '18 at 18:17
  • @Strikegently, Where do the ADO.net Libs live? I don't see it in Nuget as expected. – Greg Gum Sep 24 '18 at 18:19
  • [Is ADO.NET in .NET Core possible?](https://stackoverflow.com/questions/38510740/is-ado-net-in-net-core-possible) – Igor Sep 24 '18 at 18:20
  • @Igor, thank you that resolved it for me. If you want to post an answer, I will accept. – Greg Gum Sep 24 '18 at 18:28

0 Answers0