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
Topics
table 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@TopicId
or@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@TopicId
and@Version
. Not that the@Version
must include miliseconds.
CreateTopic
: Creates a new topic based on a@ParentId
, anAttributeValues
list 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
, anAttributeValues
list 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@Attributes
parameter.UpdateExtendedAttributes
: Updates the extended attributes, assuming the@ExtendedAttributes
parameter doesn't match the previous value.
UpdateReferences
: Associates a reference with a topic based on a@TopicId
and aTopicReferences
array of@ReferencKey
s and@Target_TopicId
s. Optionally deletes unmatched references.UpdateRelationships
: Associates a relationship with a topic based on a@TopicId
,TopicList
array of@Target_TopicIds
, and a@RelationshipKey
(which can be any string label). Optionally deletes unmatched relationships.
GetTopicID
: Retrieves a topic'sTopicId
based on a corresponding@UniqueKey
(e.g.,Root:Configuration
).GetUniqueKey
: Retrieves a topic'sUniqueKey
based on a corresponding@TopicID
.GetParentID
: Retrieves a topic's parent'sTopicID
based the child's@TopicID
.GetAttributes
: Given a@TopicID
, provides the latest version of each attribute value from bothAttributes
andExtendedAttributes
, excluding key attributes (i.e.,Key
,ContentType
, andParentID
).GetChildTopicIDs
: Given a@TopicID
, returns a list ofTopicID
s that are immediate children.GetExtendedAttribute
: Retrieves an individual attribute from a topic's latestExtendedAttributes
record.FindTopicIDs
: Retrieves allTopicID
s under a given@TopicID
that match the@AttributeKey
and@AttributeValue
. Accepts@IsExtendedAttribute
and@UsePartialMatch
parameters.
The majority of the views provide records corresponding to the latest version for each topic. These include:
AttributeIndex
: IncludesTopicId
,AttributeKey
and nullableAttributeValue
.ExtendedAttributesIndex
: IncludesTopicId
andAttributeXml
.RelationshipIndex
: Includes theSource_TopicID
,RelationshipKey
,Target_TopicID
, andIsDeleted
.ReferenceIndex
: IncludesSource_TopicID
,ReferenceKey
, and nullableTarget_TopicID
.VersionHistoryIndex
: Includes up to the last fiveVersion
records 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 anAttributeKey
Varchar(128)
andAttributeValue
Varchar(255)
columns.TopicList
: Defines a table with a singleTopicId
Int
column for passing lists of topics.TopicReferences
: Defines a table with aReferenceKey
Varchar(128)
and aTarget_TopicId
Int
column for passing lists of topic references.