Support TVP directly InList as IEnumerable
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 a branch here https://github.com/osexpert/Dapper/tree/TVPParameters
I have added support for TVP directly as argument.
Example:
SqlMapper.Settings.InListTVPCount = 1;
var list = new List<int>();
list.Add(42);
// Add some extras, to see that it works with many arguments:
for (int i = 100; i < 100000; i++)
list.Add(i);
var res = conn.Query("select * from persons where id in @ids", new { ids = list });
The table types must currently be created outside of Dapper.
A few types are handled by default (byte, short, int, long, Guid).
Other types can be added, eg:
SqlMapper.Settings.InListTVPHandlers.Add(typeof(DateOnly), new() { IdColumn = "Id", TypeName = "Dapper_DateOnly" });
And create the type is ms sql:
CREATE TYPE dbo.Dapper_DateOnly AS TABLE (Id date NOT NULL)
There is no tests written yet, but I will write some if this is something that can be merged.
It is also possible to add a way to get the table types created. Must still be done manually, but then at least can call a method in Dapper to create them (or get the sql for them) instead of doing this all manually.
Thanks.
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
Review the TVPParameters branch and the SqlMapper.Settings.InListTVPCount and InListTVPHandlers entry points first. Add tests for the IEnumerable example, the built-in types, and a custom handler, then verify the SQL Server table-type requirements and define whether table-type creation is in scope.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, sql
- Domain
- database
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100