Move some DB type casting behavior to the type objects