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.TopicReferences: Represents (1:1) references between topics, segmented by aReferenceKey.Relationships: Represents (1:n) relationships between topics, segmented by aRelationshipKey.
Note: The
Topicstable is not subject to tracking versions. Changes to core topic values, such asTopicKey,ContentType, andParentID, 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,TopicReferences, 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 and all descendant based on a@TopicId.MoveTopic: Moves an existing topic based on a@TopicId,@ParentId, and an optional@SiblingId.UpdateTopic: Updates an existing topic based on a@TopicId, anAttributeValueslist of@Attributes, and an XML@ExtendedAttributes. Old attributes are persisted as previous versions.UpdateAttributes: Updates the indexed attributes, optionally removing any whose values aren't matched in the provided@Attributesparameter.UpdateExtendedAttributes: Updates the extended attributes, assuming the@ExtendedAttributesparameter doesn't match the previous value.
UpdateReferences: Associates a reference with a topic based on a@TopicIdand aTopicReferencesarray of@ReferencKeys and@Target_TopicIds. Optionally deletes unmatched references.UpdateRelationships: Associates a relationship with a topic based on a@TopicId,TopicListarray of@Target_TopicIds, and a@RelationshipKey(which can be any string label). Optionally deletes unmatched relationships.
GetTopicID: Retrieves a topic'sTopicIdbased on a corresponding@UniqueKey(e.g.,Root:Configuration).GetUniqueKey: Retrieves a topic'sUniqueKeybased on a corresponding@TopicID.GetParentID: Retrieves a topic's parent'sTopicIDbased the child's@TopicID.GetAttributes: Given a@TopicID, provides the latest version of each attribute value from bothAttributesandExtendedAttributes, excluding key attributes (i.e.,Key,ContentType, andParentID).GetChildTopicIDs: Given a@TopicID, returns a list ofTopicIDs that are immediate children.GetExtendedAttribute: Retrieves an individual attribute from a topic's latestExtendedAttributesrecord.FindTopicIDs: Retrieves allTopicIDs under a given@TopicIDthat match the@AttributeKeyand@AttributeValue. Accepts@IsExtendedAttributeand@UsePartialMatchparameters.
The majority of the views provide records corresponding to the latest version for each topic. These include:
AttributeIndex: IncludesTopicId,AttributeKeyand nullableAttributeValue.ExtendedAttributesIndex: IncludesTopicIdandAttributeXml.RelationshipIndex: Includes theSource_TopicID,RelationshipKey,Target_TopicID, andIsDeleted.ReferenceIndex: IncludesSource_TopicID,ReferenceKey, and nullableTarget_TopicID.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.TopicReferences: Defines a table with aReferenceKeyVarchar(128)and aTarget_TopicIdIntcolumn for passing lists of topic references.