Hi all,
I been off working in the M$ land with Entity Framework and I have an app I need to do in Xojo that will require a database but is not like your typical app where I need to show things in listboxes. I need to basically save and get data from the database and in the app have it represented in classes I create sort of like in Entity Framework. I’m wondering how people are doing this with Xojo?
I understand DatabaseRecord, RecordSet etc and while I can certainly code up routines myself to move data from those Xojo objects to my own classes I’m wondering if there is a cleaner way?
Example:
I have a user table in the SQL database. Assume it has ID, username, password, phone, etc.
In my app I have a UserClass and it would have properties or holders of some kind to basically match the data in the database. So I’d have ID, username, password, phone etc.
I execute a query to find a user and I get back a RecordSet with one record in it. All that I get and feel good about. But what is the best way to move the data from field types in RecordSet into my UserClass and if edits are made send them back using a DatabaseRecord?
I was trying to keep all database knowledge in a database class I have. This not only knows how to connect but has some methods to take a UserClass and put it to the database by copying the fields from the class into a DatabaseRecord. My problem is that no matter how I do it I cannot seem to keep the knowledge separate and discrete. IE if I have a method in my database class to do this it has to know a lot about UserClass. If I make UserClass responsible for translating to/from DatabaseRecord and RecordSet then it too needs to know too much about the database to fill in the fields.
I have considered that perhaps all of my classes that will hold database related stuff might have properties for a DatabaseRecord and a RecordSet so a specific class would know how to populate and extract from these properties within itself and I could allow these to be used in the actual database queries.
Another alternative I’ve considered is simply having a Dictionary in each of my classes that gives me a link between my property that holds the data and the database field name.
Anyway, lots of ideas on how to do this, not sure which one is the best. With my current scheme of keeping everything in my database class I find I’m writing a lot of code to move things between my app classes and the database. I basically for each object need a get/put routine as well a find and query routines that know how to work with that particular class. I am hoping there is an easier way.
Thanks in advance for any ideas!