User-14642827 posted
How would get the below data using entity framework?
public int InsertPersonActivityLog(int logId, string edi, string personFormalName, DateTime activityDateTime, string activityTypeDescriptor, string additionalDetails, string reasonMessage, string notes)
{
StringBuilder errorMessages = new StringBuilder();
try
{
// Get the connection string from the appsettings.json.
conn.ConnectionString = myConn.DefaultConnectionString(configuration); // Open the connection.
conn.Open();
cmd.Connection = conn;
// Set the command type of the command object.
cmd.CommandType = System.Data.CommandType.StoredProcedure;
// Assign values as "parameters to avoid 'SQL Injections.'"
cmd.Parameters.AddWithValue("@edi", edi);
cmd.Parameters.AddWithValue("@formalName", personFormalName);
cmd.Parameters.AddWithValue("@date", activityDateTime);
cmd.Parameters.AddWithValue("@descriptor", activityTypeDescriptor);
cmd.Parameters.AddWithValue("@details", additionalDetails);
cmd.Parameters.AddWithValue("@reason", reasonMessage);
cmd.Parameters.AddWithValue("@notes", notes);
return cmd.ExecuteNonQuery();
}
catch(SqlException ex)
{
for (int i = 0; i < ex.Errors.Count; i++)
{
errorMessages.Append("Index #" + i + "\n" +
"Message: " + ex.Errors[i].Message + "\n" +
"LineNumber: " + ex.Errors[i].LineNumber + "\n" +
"Source: " + ex.Errors[i].Source + "\n" +
"Procedure: " + ex.Errors[i].Procedure + "\n");
}
Console.WriteLine(errorMessages.ToString());
}
finally
{
conn.Close();
conn.Dispose();
}
return 0;
}