The OnTopic.Data.Sql.Database provides a default schema for supporting the SqlTopicRepository.
Note: In addition to the objects below—which are all part of the default
[dbo]schema—there is also a[Utilities]schema which provides stored procedures for use by administrators in maintening the database.
The following is a summary of the most relevant tables.
Topics: Represents the core hierarchy of topics, encoded using a nested set model.Attributes: Represents key/value pairs of topic attributes, including historical versions.ExtendedAttributes: Represents an XML-based representation of non-indexed attributes, which are too long forAttributes.Relationships: Represents relationships between topics, segmented by aRelationshipKey.
Note: Neither
TopicsnorRelationshipsare subject to tracking versions. Changes to these records are permanent.
The following is a summary of the most relevant stored procedures.
GetTopics: Based on an optional@TopicIdor@TopicKey, retrieves a hierarchy of topics, sorted by hierarchy, alongside separate data sets for corresponding records fromAttributes,ExtendedAttributes,Relationships, and version history. Only retrieves the latest version data for each topic.GetTopicVersion: Retrieves a single instance of a topic based on a@TopicIdand@Version. Not that the@Versionmust include miliseconds.
CreateTopic: Creates a new topic based on a@ParentId, anAttributeValueslist of@Attributes, and an XML@ExtendedAttributes. Returns a new@TopicId.DeleteTopic: Deletes an existing topic based on a@TopicId.MoveTopic: Moves an existing topic based on a@TopicId,@ParentId, and@SiblingId.UpdateTopic: Updates an existing topic based on a@TopicId, anAttributeValueslist of@Attributes, and an XML@ExtendedAttributes. Optionally deletes all relationships; these will need to be re-added usingUpdateRelationships. Old attributes are persisted as previous versions.UpdateRelationships: Associates a relationship with a topic based on a@TopicId,TopicListarray of@Target_TopicIds, and a@RelationshipKey(which can be any string label).
GetTopicID: Retrieves a topic'sTopicIdbased on a corresponding@TopicKey.GetParentID: Retrieves a topic's parent'sTopicIdbased the child's@TopicId.
The majority of the views provide records corresponding to the latest version of records for each topic. These include:
TopicIndex: Includes the core topic attributes,topicId,Key,ParentId, andContentType.AttributeIndex: Includes theTopicId,AttributeKeyandAttributeValue.ExtendedAttributesIndex: Includes theTopicIdandAttributeXml.VersionHistoryIndex: Includes up to the last fiveVersionrecords for everyTopicId.
User-defined table valued types are used to relay arrays of information to (and between) the stored procedures. These can be mimicked in C# using e.g. a DataTable. These include:
AttributeValues: Defines a table with anAttributeKeyVarchar(128)andAttributeValueVarchar(255)columns.TopicList: Defines a table with a singleTopicIdIntcolumn for passing lists of topics.