mli mli - 1 month ago 16
MySQL Question

Dapper insert syntax

I use orm dapper from c# application for mysql database access. It works fine. There's only syntax question. I have a class with a many properties. All this properties matches database table fields exactly. So Select request is pretty short:

var listOfInstances = con.Query<MyClass>("Select * From myTable");


but when I need to insert something into database I have to write all those properties names that looks a little bit ugly:

con.Execute(@"Insert into myTable values(@Id, @Property1, @Property2, @Property3, @Property4, ....)", listOfInstances);


I wonder if there are any shorter syntax to insert data, at least for such a case when all class properties matches database table fields exactly.

P.S. The same thing about Update request

P.P.S. If say honestly I just start to work with a database which contains many tables, so I had to write basic functions get/add/change instance for each of those tables and it is quite annoing to list all of their fields.

Answer