Problems with SqlMapper.TypeHandler<List<string>>
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 18.4k
- Forks
- 3.7k
- Avg merge
- 5h 8m
- Merged PRs (30d)
- 1
Description
I'm trying to resolve a problem with a class that contains a List<string> property.
In this case, when I use a QueryFirstOrDefault, Dapper does not fill the property correctly, throwing an error.
I'd like to receive an object of the class, with the property filled with a list of one item.
For that, I've created this:
public class ListStringTypeHandler : SqlMapper.TypeHandler<List<string>>
{
public override void SetValue(IDbDataParameter parameter, List<string> value)
{
parameter.Value = string.Join(",", value);
}
public override List<string> Parse(object value)
{
if (value == null || value is DBNull)
return new List<string>();
if (value is string stringValue)
return new List<string> { stringValue };
return new List<string>((IEnumerable<string>)value);
}
}
But, after that, every single query that contains a IN clause, don't work more.
Are there any way to override only Parse method ?
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
The issue names SqlMapper.TypeHandler<List> and QueryFirstOrDefault, but no repository files or tests. Start by locating type-handler registration and IN-clause parameter handling, then reproduce the behavior with the provided handler and a List property. Done means the interaction is understood and covered by a focused test or documented resolution.
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