1. Do they support the preparation of the request or is each request compiled on a new one?

  2. I understand correctly that if the connection is closed, then it opens it for the duration of the request, and then closes it? If the connection is initially open, is it maintained until I close it myself?

  3. In Dapper, you can do this Execute("INSERT INTO Table(f1,f2) values(@f1,@f2)",List) where List is a list of several objects to insert. Will it insert 1 record or generate queries from the N lines of the List and insert it?

  • 2) it does not control the connection at all. These are just extension methods to the connect instance. - vitidev
  • If you are given an exhaustive answer, mark it as correct (tick the selected answer). - andreycha

1 answer 1

  1. Compiling queries is engaged in the database. If we talk about preparation, then no, Dapper does not prepare requests . However, there is some internal cache that allows you to materialize objects faster. Moreover, if you use parameters and execute the same query many times, the cache will take this into account.

    It is a matter of fact.

  2. As @vitidev rightly pointed out, Dapper provides extension methods for connecting. Previously, he really did not manage the connection state and required an open connection. However, now he opens closed connections ( one , two ) and, accordingly, closes them. At the same time, it is still possible to transfer an open connection to it and documentation to many methods still states that an open connection is required.

  3. Yes you can . As for exactly how such an operation is performed, I will not say. It is necessary either to read the source, or to try and look in the profiler. (If you suddenly need to use bulk insert, there is a Dapper Plus add-on.)

     connection.Execute(@"insert MyTable(colA, colB) values (@a, @b)", new[] { new { a=1, b=1 }, new { a=2, b=2 }, new { a=3, b=3 } } ).IsEqualTo(3); // 3 rows inserted: "1,1", "2,2" and "3,3" 
  • I added 3 questions, do not answer it further? - iluxa1810
  • @ iluxa1810 updated the answer. - andreycha