Any dapper performance difference when just passing the object?

.net c# dapper micro-orm orm

Question

So I've been using dapper for a few of my projects lately, and I was curious if there was any performance difference between the following samples:

With an object with many properties 30+ is there any benefit to explicitly stating the properties as opposed to just letting it figure it out on its own?

Option 1:

string sqlQuery = @"INSERT INTO [PTTicket]
                                     ([Id])
                               VALUES
                                     (@Id)";
con.Execute(sqlQuery, ptTicket);

Option 2:

string sqlQuery = @"INSERT INTO [PTTicket]
                                     ([Id])
                               VALUES
                                     (@Id)";
con.Execute(sqlQuery, 
                     new 
                     { 
                         ptTicket.Id 
                     }

I'm just curious if there's any benefit to manually providing the values, or if I can just pass the object and let Dapper have it's way.

Especially as the list starts to grow:

Option 1b

string sqlQuery = @"INSERT INTO [PTTicket]
                                         ([Id]
                                         ,[Name]
                                         ,[SMState]
                                         ,[CreatedByMember]
                                         ,[StartDate]
                                         ,[ClosedDate]
                                         ,[Remarks])
                                   VALUES
                                         (@Id
                                         ,@Name
                                         ,@SMState
                                         ,@CreatedByMember
                                         ,@StartDate
                                         ,@ClosedDate
                                         ,@Remarks)";
con.Execute(sqlQuery, ptTicket);

Option 2b.

string sqlQuery = @"INSERT INTO [PTTicket]
                                       ([Id]
                                       ,[Name]
                                       ,[SMState]
                                       ,[CreatedByMember]
                                       ,[StartDate]
                                       ,[ClosedDate]
                                       ,[Remarks])
                                 VALUES
                                       (@Id
                                       ,@Name
                                       ,@SMState
                                       ,@CreatedByMember
                                       ,@StartDate
                                       ,@ClosedDate
                                       ,@Remarks)";
con.Execute(sqlQuery,
                    new
                    {
                        ptTicket.Id,
                        ptTicket.Name,
                        ptTicket.SMState,
                        ptTicket.CreatedByMember,
                        ptTicket.StartDate,
                        ptTicket.ClosedDate,
                        ptTicket.Remarks
                    });

Accepted Answer

In the case of inline TSQL, no, they should be about the same. Dapper does some brief inspection of the command to decide which properties to send, but it is pretty basic. If you had a comment like:

-- phew, it is a good job we didn't pass in @LongDescription, because
-- that could be 2GB in size!

then that could be enough to make dapper send .LongDescription.

If you are using stored procedures, then no such inspection is possible, so it will send everything it can see.




Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why