Tomas

Tomas

  • NA
  • 7
  • 0

Custom value type in where clause

Feb 26 2009 6:48 AM
Hi,

I have a struct (see code below) that I want to use as parameter in a where clause on a sql query. I want it to be treated as a string when the query executes but I get this message: "No mapping exists from object type [MyStruct] to a known managed provider native type.". Can I somehow give a hint that I want to use the value in the member Value and that it is a string? I have tried IConvertible with no luck. It must work on Oracle, MySql and SQL Server. Also see call stack below (SQL Server).

internal struct MyStruct
{
    public readonly string Value;

    // more code...
}

System.Data.SqlClient.MetaType.GetMetaTypeFromValue(Type dataType, Object value, Boolean inferLen)
System.Data.SqlClient.SqlParameter.GetMetaTypeOnly()
System.Data.SqlClient.SqlParameter.Validate(Int32 index, Boolean isCommandProc)
System.Data.SqlClient.SqlCommand.BuildParamList(TdsParser parser, SqlParameterCollection parameters)
System.Data.SqlClient.SqlCommand.BuildExecuteSql(CommandBehavior behavior, String commandText, SqlParameterCollection parameters, _SqlRPC& rpc)
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader()
...

Thanks in advance,
Tomas

Answers (7)