I've got a custom type which i produced, that ought to be endured inside a database (within this situation, SQL server) like a guid (though this is equally as valid to have an object that may be saved like a string, integer, etc).
After I pass this kind like a parameter to some DbCommand object, I recieve the best:
ArgumentException: No mapping is available from object type [...] to some known handled provider native type.
I've CType operators around the class that permit implicit conversion to some string, or perhaps a guid, but .Internet does not begin using these because it does not realize it should convert the kind.
It is possible to method to give a type towards the internal mapping, or else tell .Internet how you can store my custom enter in the database?
I clearly can convert the kind myself when passing it towards the .Internet stuff, but I would like this to occur instantly, enjoy it does for the majority of the built-in types.
I have attempted to implement a TypeConverter class for my type (gets from TypeConverter, overrides CanConvertFrom, CanConvertTo, ConvertFrom, ConvertTo, IsValid, and added the machine.ComponentModel.TypeConverter attribute to my class), but this still does not work.
I am presuming it's missing an item telling .Internet what kind to transform to when storing the worthiness within the database.
My workaround with this, for the time being, is the fact that I intercept their email list of parameters, before I pass these to SQL server, and also have a method that changes my custom type right into a guid. This really is dirty, however it works for the time being, however i still think this is un-answered.
Based on http://stackoverflow.com/questions/767072/how-should-i-pass-a-user-defined-type-to-sqlparametercollection-addwithvalue, it isn't possible. I have checked out the GetMetaTypeFromValue method too, also it appears like all of the mapping is actually hardcoded within the framework, thus no user-defined mapping can be done.
How annoying, it might be really helpful with an attribute that defines mapping for any given type.
Here are a few links to Type Converters insInternet