Insert using Dapper and Always Encrypted
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 18.4k
- Forks
- 3.7k
- Avg merge
- 5h 8m
- Merged PRs (30d)
- 1
Description
Hello, I use "Sql Server Management Studio 2016" and "Visual Stuido 2015", my project is a C# project.
I have a problem when I' trying to insert some rows with encrypted columns with Always Encrypted.
In the databse, "base_salary" is a NUMERIC(11, 3).
This is my class Effective :
public class Effective
{
public int id {get; set;}
public string matricule { get; set; }
public string name { get; set; }
public string firstname { get; set; }
public double base_salary { get; set; }
}
When it was'nt encrypted, I was using this :
effective.id = connection.Query<int>(
@"INSERT INTO Effective (matricule, name, firstname, base_salary)
VALUES(@matricule, @name, @firstname, @base_salary);
SELECT CAST(SCOPE_IDENTITY() as int)", effective
).Single();
Now, my column "base_salary" is encrypted with Always Encrypted and it isn't working anymore. to bypass this I use :
string sql = "INSERT INTO effective (matricule, name, firstname, base_salary) VALUES (@matricule, @name, @firstname, @base_salary)";
SqlCommand query = new SqlCommand(sql);
query.Connection = connection;
query.Parameters.Add("@matricule", SqlDbType.NVarChar, 6).Value = effective.matricule;
query.Parameters.Add("@name", SqlDbType.NVarChar, 50).Value = effective.name;
query.Parameters.Add("@firstname", SqlDbType.NVarChar, 50).Value = effective.firstname;
SqlParameter base_salary = new SqlParameter("@base_salary", SqlDbType.Decimal);
base_salary.Precision = 11;
base_salary.Scale = 3;
base_salary.Value = effective.base_salary;
query.Parameters.Add(base_salary);
So, can you explain me what I'm doing wrong with Dapper or if it's a problem ?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No repository file or test is named; start by comparing the Dapper Query call with the explicit SqlCommand and typed Decimal parameter shown in the issue. Reproduce the insert with Always Encrypted and determine whether Dapper's object-parameter binding handles the encrypted decimal column; done means documenting the cause and the supported usage or limitation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, sql
- Domain
- database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100