## 21 EODataSource class

### 21.1 overview

EODataSource is an abstract base class, and implements no real functionality on its own, instead you’ll access EODataSource subclass.

A data source represents a collection of rows inside of a table. It can create rows, delete and provide access to the individual rows represented as Enterprise objects.

Typical methods for an EODataSource subclass:

1. -fetchObjects
2. -createObject:
3. -deleteObject:
4. -insertObject:
5. -dataSourceQualifiedByKey:

### 21.2 Fetch objects

The -fetchObjects method will return an array of enterprise objects. Typically these will be retrieved directly from data in the database server. Then the caller will save the array for access or modification.

### 21.3 Creating objects

The -createObject: method will create a new enterprise object for insertion into the database. A subclass will generally insert this new object into an editing context. Though the caller is responsible for inserting the object into the data source with -insertObject:.

### 21.4 Inserting objects

The -insertObject: method will schedule the object for addition into the database server EditingContexts changes are saved to the database.

### 21.5 Deleting objects

The -deleteObject: method will schedule the object for removal from the database server when the EOEditingContexts changes are saved to the database.

### 21.6 Qualified DataSources

Subclasses may implement this method to return a detail data source.

A detail data source is a datasource which is created from following a relationship in an object of the receiever: the master object.

in our example you might have a data source for the authors entity and qualify a detail data source, with the toBooks key.

### 21.7 EODatabaseDataSource class

EODatabaseDataSource class is a subclass of EODataSource.

To initialize an EODatabaseDataSource you’ll give it a reference to an EOEditingContext and an entity name.

EODatabaseDataSource initializers:

1. -initWithEditingContext:entityName:
2. -initWithEditingContext:entityName:fetchSpecificationName:

Once initialized, you can call the EODataSource methods on it, to create fetch insert, and delete objects from the datasource.