What would be a more appropriate way to do data access from an Azure function to Azure SQL DB. In my case, it will an HTTP triggered function. I need to parse the message body and insert the data in a DB table. I have already created the table in the database.
I extracted the required properties from the JSON body and formed a hard-coded sql statement like so,
var text = "INSERT INTO dbo.customer VALUES ("
                + customerData.id
              + ", '" + customerData.prefix + "'"
              + ", '" + customerData.firstname + "'"
              + ", '" + customerData.lastname + "'"
    
                + ")";
    //I have tried using this method
            using (SqlConnection conn = new SqlConnection(str))
            {
                conn.Open();
                
                using (SqlCommand cmd = new SqlCommand(text, conn))
                {
                    // Execute the command and log the # rows affected.
                    var rows = await cmd.ExecuteNonQueryAsync();
                    log.LogInformation($"{rows} rows were updated");
                }
          }
This works for this simple insert but, I feel like this is not ideal for a solution. I am not able to find many examples where Azure Functions are used to access Azure SQL DB. Should I use EF Core or the current method needs to be modified? Please suggest Thanks
 
     
    