Query<T>() issue with array bound parameter (Oracle)
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 18.4k
- Forks
- 3.7k
- Avg merge
- 5h 8m
- Merged PRs (30d)
- 1
Description
Hi guys.
I like Dapper very much, it helps in some areas where EF can't work efficiently.
However I found that Query() method doesn't accept array value for array bound parameter.
I have the code lie this:
public IEnumerable<ModelElementDto> GetChildGeometry(int[] parentIDs)
{
var param = parentIDs.Select(p => new { ParentId = p}).ToArray();
var modelElemets = Context.Database.Connection.Query<ModelElementEntity>(@"select * from PRO_MODEL_ELEMENTS start with parent_Id = :ParentId connect by parent_Id = prior id", param);
var mapper = AutoMapperDataConfiguration.Config.CreateMapper();
var retList = mapper.Map<List<ModelElementDto>>(modelElemets);
return retList;
}
I want my parentIDs array to be bound to :ParentId parameter, so I can read bunch of rows in the single query. However Dapper returns this error:
An enumerable sequence of parameters (arrays, lists, etc) is not allowed in this context
at Dapper.SqlMapper.GetCacheInfo(Identity identity, Object exampleParameters, Boolean addToCache)
at Dapper.SqlMapper.<QueryImpl>d__125'1.MoveNext()
at System.Collections.Generic.List'1..ctor(IEnumerable'1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable'1 source)
at Dapper.SqlMapper.Query[T](IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Boolean buffered, Nullable'1 commandTimeout, Nullable'1 commandType)
Are there any reasons why Query prohibits an array bound parameters?
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
Start by tracing Query into SqlMapper.GetCacheInfo and reproduce the reported error with the Oracle query and array of parent IDs shown in the issue. Determine how array-bound parameters should be handled in this context, then verify that the query can return rows for all supplied IDs without the enumerable-parameter exception.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, sql
- Domain
- backend, database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100