I have a two part question - one for clarification and one for education.
I understand that the various SmartXYZ types that have been created expose a DBValue property to overcome the "No mapping exists from object type Csla.SmartXYZ to a known managed provider native type" exception. But why go this route and not implement whatever it takes to provide this mapping so that the type can be used outright like their System counter-parts?
And with that in mind, what is it that the framework classes do or implement that allow them to be mapped? Is it via an interface, a type converter or something else?
I implemented IConvertible.GetTypeCode and return System.TypeCode.DateTime then tried to use the SmartDate type directly but it still failed. Placing a breakpoint in GetTypeCode never broke execution, telling me this isn't the key. So how do the built-in classes do it?
No one has any feedback/thoughts on this?
Sorry for the delay responding...
I realize what purpose the DBValue properties serve, what I would like to know is if they are really necessary or if some other means is available to accomplish the same requirement.
In tracing through the SqlClient classes using ILDASM to see what is done with property values, I found that there is a GetMetaDataFromType method that appears to use the specified type's GetTypeCode() value in a switch statement (Select Case in VB) to translate the type to the applicable SqlType. If the return type code is not one of the switch cases, the aforementioned exception is thrown.
It appears, but I'm not sure, that there is a second test to validate the type of the specified object with an exception thrown if it doesn't match. For instance, if GetTypeCode returns TypeCode.DateTime there is a test to verify that (obj is System.DateTime). This may be where the problem lies - even though I still don't get a hit when I set a breakpoint in the GetTypeCode method for the SmartDateTime struct. So, can we return the Object type code instead and circumvent this?
Or am I barking up the wrong tree entirely?
Copyright (c) Marimer LLC