|
FoxDataObjects |
Object-Relational Mapping Tool for Visual FoxPro® |
|
|
API Reference - Quick Start |
||
|---|---|---|
Assuming your persistent classes has been defined and mapped (either automatically by the mapping engine or by using the Schema Manager mapping tool), all your code need to do to gain access to all the FoxDataObjects API services is to issue a:
SET PROCEDURE TO fdo ADDITIVE
This simple line of code opens an amazing new world of possibilities to your business objects. The next examples shows a basic usage of persistence services.
First step is to create a Server object that will enable us to get fully connected Session objects.
oServer = CREATEOBJECT("fdoServer")
The Server object allows to define default values for new Session objects, like a default datasource object, default mapping schema file, and so on. To simplify, lets use the datasource object for Visual FoxPro databases automatically created on Server object instantiation.
oServer.DefaultDataSource.Database_Path="C:\MyData\"
oServer.DefaultDataSource.Database_Name="Contacts"
Let's create our Session object:
oSession.oServer.NewSession("Contacts.FDO")
Now we are connected to the database, the database schema is up to date and we are ready to save/retrieve/remove objects from the database.
oCustomer = CREATEOBJECT("customer")
oCustomer.FullName = "John Strass"
oCustomer.Address = CREATEOBJECT("address")
oCustomer.Address.Street = "362 St.Martin Avenue"
oCustomer.Address.City = "New York"
And save the object to the database:
oSession.SaveObject(oCustomer)
To retrieve a simple object we can use something like:
oJohn=oSession.GetObject("customer","FullName LIKE 'Strass' AND Address.City='New York'")
? oJohn.FullName ---> "John Strass"
? oJohn.Address.Street ---> "362 St.Martin Avenue"
And to remove the object from the database :
oSession.DeleteObject(oJohn)
To query for a set of objects:
oQuery=oSession.NewQuery("SELECT OBJECTS FROM customer WHERE customer.address.state='NY'")
? "There are ",oQuery.Count," customers in NY"
FOR EACH oCustomer IN oQuery.ITEM
? oCustomer.FullName,oCustomer.Address.Street
ENDFOR
And it is just the beginning...
Do you see, in the previous samples, any SQL statement, CREATE TABLE , SELECT, INSERT , UPDATE, or connection statement ?
No. All of this work is done for you by FoxDataObjects. Just change your datasource object, and it will work again on a completely different database !!,
... and you've just used five easy to use persistence methods.
|
Send feedback on this topic to RunAhead Technologies For Technical support and product issues please contact us at support@foxdataobjects.com or visit http://www.foxdataobjects.com |
Copyright (c) 2000-2005 RunAhead Technologies