Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

When specifying the type to return, these calls support using parent types and interfaces, including object, as a way of representing that content of a group of different types should be returned.  The data returned can then be cast to the appropriate type to perform operations associated with that type.

Methods

Getting Data

Code Block
languagec#
T Get<T>()
T Get<T, TContent>()

This simply gets all content records stored whose type can be assigned to type T. If T is a summary type, it returns all the summaries that can be assigned to that type.  The second cast works as the first, except only records whose content type is TContent are returned.  This is useful for e.g. to get the summaries for a specific content type.

Code Block
languagec#
T Get<T>(RouteData rd)
T Get<T>(Type contentType, RouteData rd)

For a given request, when processed into RouteData, this method returns the content item of type T associated with it.  If no content item has been created which is associated with this request, null is returned.

...

The second signature allows for specifying the content type required: this allows for T to be a summary type.

Code Block
languagec#
T Get<T>(Address address)
IEnumerable<T> Get<T>(IEnumerable<Address> addresses)

The Address class is an intermediary representation which can be extracted from either a url (in the form of RouteData) or an actual content item to uniquely identify it in terms of its natural url address.  These methods return the content item or items found at an address or addresses.

T can be a content type to return content items, or a summary type to return summaries, in which case any item whose summary is not assignable to T will be ignored.

Code Block
languagec#
T Get<T>(ItemId id)
IEnumerable<T> Get<T>(IEnumerable<ItemId> ids)

The ItemId class contains a unique record identifier plus a type, so it will uniquely identify any content item available from the data API.  ItemVersionedId inherits from ItemId and can be used in these methods to further specify the version of the content item required.

...

T can be a content type to return content items, or a summary type to return summaries, in which case any item whose summary is not assignable to T will be ignored.

Code Block
languagec#
IEnumerable<T> Get<T, TQuery>(Func<IQueryable<TQuery>, IQueryable<TQuery>> queryBody)
IEnumerable<T> Get<T, TQuery>(IEnumerable<Type> types, Func<IQueryable<TQuery>, IQueryable<TQuery>> queryBody)

These methods use a query to return a number of content items.  In order to be able to internally compose the query from any data source, the query argument is specified as a mapping from the data source IQueryable to the data output IQueryable.  An example would be iq => iq.Where(x => x.Name = "tim").

...

In the second case, the query is run across the data sources for all the types assignable to the 'types' parameter.  In the first case, all types which can be assigned to T are used.

Changing Data

Code Block
languagec#
bool Set(object data)
bool Set(object data, bool? create)
bool Set(Address address, object data)
bool Set(Address address, object data, bool? create)
bool Set(Address address, object data, bool? create, bool bypassChecks)
bool Set(Address address, object data, Dictionary<string, object> setOptions)

The above calls are used to update or create a content item.  Generally the second type is only needed where the data object has no attached record of its metadata, and therefore the API does not know at what address to save it.  Inheritors fromBaseContent will have their metadata attached and so do not need an address supplied.

...

The bool value returned is whether the item was added as a new content item.

Code Block
languagec#
void Delete(object data)
void Delete(Address address, object data)
void Delete(Address address, object data, bool bypassChecks)

These calls work similarly to Set, but delete the relevant data item. Again the bypassChecks flag can be set to avoid alteration of the call by modules or blocking by consistency and error checking.