C#C
C#2y ago
Alice

how to use OID parameter in Dapper

Hi guys,
I'm trying to use Dapper to query sql database, but the problem is my batchId is a string, and in the database batchId is an OID.
I have tried to convert from string to Oid, but I got error said dapper doesn't support this type.

The member batchId of type System.Security.Cryptography.Oid cannot be used as a parameter value

May I know how to handle this scenario?
Thanksss!!

public virtual async Task<GetTDataDTO> GetData(string batchId) { //batchId example: 0x30c4b63ee3050080 var result = new GetTDataDTO(); Oid batchOid = new Oid(batchId); var sqlSelect= @" SELECT * FROM data_table fls WITH (NOLOCK) WHERE batchId = @batchId "; var parameters = new DynamicParameters(); parameters.Add("batchId", batchOid); using (var conn = new SqlConnection(ConnectingString)) { var result = await conn.QueryAsync<GetTDataDTO>(sqlSelect.ToString(), parameters); } return result; }
Was this page helpful?