Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The byte data type is not supported by the IN clause #2065

Open
mkorsukov opened this issue Apr 2, 2024 · 0 comments
Open

The byte data type is not supported by the IN clause #2065

mkorsukov opened this issue Apr 2, 2024 · 0 comments

Comments

@mkorsukov
Copy link

Intro

Looks like Dapper doesn't support byte data type in the IN clause.

Microsoft.Data.SqlClient.SqlException (0x80131904): Incorrect syntax near '@Types'.
   at Microsoft.Data.SqlClient.SqlCommand.<>c.<ExecuteDbDataReaderAsync>b__195_0(Task`1 result)
   at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke()
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
   at Dapper.SqlMapper.QueryAsync[T](IDbConnection cnn, Type effectiveType, CommandDefinition command) in /_/Dapper/SqlMapper.Async.cs:line 434
   at X.Resource.Database.DatabaseClient.<>c__DisplayClass89_0`1.<<ListAsync>b__0>d.MoveNext() in /media/ramdisk/Platform/Src/Resources/Database/DatabaseClient.cs:line 190

Steps to reproduce

SQL query

select
  *
from
  [Underwriting]
where
  [LeadId] = @LeadId
  and [Type] in @Types;

C# code

// Working version
async Task<IReadOnlyList<UnderwritingDataModel>> ListAsync(int leadId, int[] types)
{
  return await ListAsync<UnderwritingDataModel>(UseSql("ListUnderwritings"), new { leadId, types });
}

// NOT working version
async Task<IReadOnlyList<UnderwritingDataModel>> ListAsync(int leadId, byte[] types)
{
  return await ListAsync<UnderwritingDataModel>(UseSql("ListUnderwritings"), new { leadId, types });
}

Dependencies

  • Dapper 2.1.37
  • Microsoft.Data.SqlClient 5.2.0
  • .NET 8.0.3
@mkorsukov mkorsukov changed the title Byte data type not supported in the IN clause The byte data type is not supported by the IN clause Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant