How should I pass a user-defined type to SqlParameterCollection.AddWithValue?
问题 I have a custom data type called StudentID , which has an implicit conversion to string. When I pass a StudentID instance to SqlCommand.Parameters.AddWithValue (as the value) and execute the command, I receive the following error: No mapping exists from object type StudentID to a known managed provider native type. Specifying a type for the parameter like SqlDbType.NVarChar doesn't help. The only thing that works is to explicitly cast the StudentID value to a string, which defeats the purpose