Automatically define classes when attaching to database