Why don’t you want to use Entity Framework? Entity Framework makes performing all aspects of data operations easier and with less maintenance and refactoring and is less prone to many issues that can happen.
Example, editing a record in EF Core
public static bool EditCustomer(Customer customer)
{
using CustomerContext context = new();
context.Entry(customer).State = EntityState.Modified;
return context.SaveChanges() == 1;
}
Now without EF Core
public static int EditCustomer(Customer customer)
{
using var cn = new SqlConnection(ConfigurationHelper.ConnectionString());
using var cmd = new SqlCommand { Connection = cn, CommandText = SqlStatements1.UpdateCustomer};
cmd.Parameters.Add("@CompanyName", SqlDbType.NChar).Value = customer.CompanyName;
cmd.Parameters.Add("@ContactName", SqlDbType.NChar).Value = customer.ContactName;
cmd.Parameters.Add("@ContactTypeIdentifier", SqlDbType.Int).Value = customer.ContactTypeIdentifier;
cmd.Parameters.Add("@GenderIdentifier", SqlDbType.Int).Value = customer.GenderIdentifier;
cmd.Parameters.Add("@Identifier", SqlDbType.Int).Value = customer.Identifier;
cn.Open();
return cmd.ExecuteNonQuery();
}
Now imagine you changed a column name in a table, with EF Core we re-reverse engineer or use migrations while without EF Core we must make manual changes. This carries through with all operations, read, edit, remove, find, add etc.
One more EF Core example, find by multiple primary keys, not that easy without EF Core
public static async Task<Customer[]> CustomersWhereInAsync(int[] primaryKeys)
{
await using CustomerContext context = new();
return await context.FindAllAsync<Customer>(primaryKeys.ToObjectArray());
}