DapperLib / DapperLib/Dapper

Dapper TVP Behavior and SQL Server Monitoring Overhead

Open
#2,170 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
18.4k
Forks
3.7k
Avg merge
5h 8m
Merged PRs (30d)
1

Description

Hi
I’m reaching out to ask for your advice regarding how Dapper sends Table-Valued Parameters (TVPs) to SQL Server and how that appears in monitoring tools such as Extended Events.

In my project, I have defined a TVP as follows:

CREATE TYPE dbo.UserDefinedParameters AS TABLE (
    Id INT,
    Value1 INT,
    Value2 INT,
    Value3 INT
)

Dapper parameters on  call store procedure command

var searchParameters = new
{
    SearchParams = table.AsTableValuedParameter("dbo.UserDefinedParameters"),
    OtherParam01 = 10,
    OtherParam02 = 20,
};

Everything works correctly, but our database team raised a concern regarding how this call is logged in Extended Events. Specifically, they noticed that each row in the TVP is being sent as a separate INSERT INTO statement, like this:

DECLARE @p1 dbo.UserDefinedParameters

INSERT INTO @p1 VALUES (1, 1, 1388, NULL)
INSERT INTO @p1 VALUES (2, 1, 1388, 603)
-- potentially hundreds more...
EXEC dbo.Search
    @SearchParams = @p1,
    @OtherParam01 = NULL,
    @OtherParam02 = NULL,
    ...


My questions are:

Is this the expected behavior from Dapper when sending TVPs?

Is there a way to batch these values or reduce the number of INSERT statements?

Have you seen this being a real issue in practice, and would you recommend any workaround or tuning?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the stored procedure call using Dapper's AsTableValuedParameter and inspect the resulting SQL Server Extended Events output. Compare the observed per-row INSERT statements with the expected TVP behavior and document whether batching or a practical workaround is available; the issue names no repository files or tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, sql
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.