DapperLib / DapperLib/Dapper

Gives wrong parameter name in Sqlite

Open
#1,368 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 have upgraded my project from .Net Core 2.2 to .Net Core 3. And now it uses Microsoft.Data.Sqlite instead of System.Data.Sqlite.
Unfortunately, Dapper doesn't work with Sqlite parameters. Try this:

string sql = @"INSERT into documents(Id, name, owner_id)
    VALUES(@id, @name, @owner_id)";

if(doc.Id == Guid.Empty)
	doc.Id = Guid.NewGuid();

var @params = new { id = doc.Id, doc.Name, owner_id = doc.Owner.Id };				
int result = await conn.ExecuteAsync(sql, @params, activeTransaction);

doc - it's just an object with some properties.
conn - it's SqliteConnection

Now, Dapper creates parameters with names: "id", "Name", "owner_id". But the names should be prefixed with '@' sign, like that: "@id", "@Name" and "@owner_id"

Without this, Sqlite throws exception: InvalidOperationException with message: "Must add values for the following parameters: @id, @name, @owner_id"

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 issue with Microsoft.Data.Sqlite, the SQL shown, and Dapper's ExecuteAsync call. Compare the generated parameter names with the names required by the reported SQLite exception; the payload does not identify a repository file or test. Done means the reproduction succeeds and a regression test covers the parameter-name behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, sqlite
Domain
backend, databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.