Search Results for

    Show / Hide Table of Contents
    note

    VeloxDB is still in beta and APIs are subject to change. We are in the process of completing the documentation, so some sections may be incomplete or empty at this time.

    Class InverseReferenceSet<T>

    Represents a set of inverse references.

    Inheritance
    object
    InverseReferenceSet
    InverseReferenceSet<T>
    Implements
    ICollection<T>
    IReadOnlyList<T>
    IReadOnlyCollection<T>
    IEnumerable<T>
    IEnumerable
    Inherited Members
    object.GetType()
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    Namespace: VeloxDB.ObjectInterface
    Assembly: vlxdb.dll
    Syntax
    public sealed class InverseReferenceSet<T> : InverseReferenceSet, ICollection<T>, IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable where T : DatabaseObject
    Type Parameters
    Name Description
    T

    The type of items in the array.

    Examples

    The following example demonstrates how to declare an InverseReferencesAttribute property.

    [DatabaseClass]
    public abstract class Blog : DatabaseObject
    {
        [DatabaseProperty]
        public abstract string Url { get; set; }
    
        [InverseReferences(nameof(Post.Blog))]
        public abstract InverseReferenceSet<Post> Posts { get; }
    }
    

    The following example demonstrates how to use an InverseReferenceSet<T>.

    [DbAPIOperation]
    public bool TestBlog(ObjectModel om)
    {
        bool result = true;
        // Create new blog.
        Blog blog = om.CreateObject<Blog>();
    
        // Create a new post.
        Post post1 = om.CreateObject<Post>();
    
        // Add a new post using direct reference.
        post1.Blog = blog;
    
        // Create another post.
        Post post2 = om.CreateObject<Post>();
    
        // Add another post to the blog, using inverse reference.
        blog.Posts.Add(post2);
    
        // Check if both posts are in blog
        result &= blog.Posts.Contains(post1);
        result &= blog.Posts.Contains(post2);
    
        // Check if both posts reference blog
        result &= post1.Blog == blog;
        result &= post2.Blog == blog;
    
        // Clear all posts
        blog.Posts.Clear();
    
        // Confirm that posts are not in blog anymore.
        result &= !blog.Posts.Contains(post1);
        result &= !blog.Posts.Contains(post2);
    
        // Check if both posts point to null.
        result &= post1.Blog == null;
        result &= post2.Blog == null;
    
        // Delete posts.
        post1.Delete();
        post2.Delete();
    
        // Delete blog.
        blog.Delete();
    
        return result;
    }
    

    Properties

    Count

    Gets the number of items in InverseReferenceSet<T>

    Declaration
    public override int Count { get; }
    Property Value
    Type Description
    int
    Overrides
    InverseReferenceSet.Count

    IsReadOnly

    Gets if the InverseReferenceSet<T> is Readonly. Always returns false.

    Declaration
    public bool IsReadOnly { get; }
    Property Value
    Type Description
    bool

    this[int]

    Index accessor.

    Declaration
    public T this[int index] { get; }
    Parameters
    Type Name Description
    int index

    Index of the item to get.

    Property Value
    Type Description
    T

    Requested item.

    Exceptions
    Type Condition
    IndexOutOfRangeException

    If index is less than 0 or greater than Count

    InvalidOperationException

    If the parent object of the DatabaseArray<T> has been deleted or abandoned.

    ObjectDisposedException

    If the parent object of the DatabaseArray<T> has been disposed.

    Methods

    Add(T)

    Add an item to InverseReferenceSet<T>.

    Declaration
    public void Add(T item)
    Parameters
    Type Name Description
    T item

    The item to be added.

    Remarks

    This is the same as creating a direct reference.

    note

    Order in InverseReferenceSet<T> is not guaranteed. Added object can appear anywhere in InverseReferenceSet<T>.

    Exceptions
    Type Condition
    ArgumentNullException

    If item is null.

    InvalidOperationException

    If the parent object of the InverseReferenceSet<T> has been deleted or abandoned.

    ObjectDisposedException

    If the parent object of the InverseReferenceSet<T> has been disposed.

    Clear()

    Clears all references.

    Declaration
    public void Clear()
    Exceptions
    Type Condition
    InvalidOperationException

    If the parent object of the InverseReferenceSet<T> has been deleted or abandoned.

    ObjectDisposedException

    If the parent object of the InverseReferenceSet<T> has been disposed.

    Contains(T)

    Determines if an item is in the InverseReferenceSet<T>.

    Declaration
    public bool Contains(T item)
    Parameters
    Type Name Description
    T item
    Returns
    Type Description
    bool

    true if item is present in the InverseReferenceSet<T>, false if not.

    Exceptions
    Type Condition
    ArgumentNullException

    If item is null.

    InvalidOperationException

    If the parent object of the InverseReferenceSet<T> has been deleted or abandoned.

    ObjectDisposedException

    If the parent object of the InverseReferenceSet<T> has been disposed.

    CopyTo(T[], int)

    Copies all items from the InverseReferenceSet<T> to the given array, starting at the specified index of the target array.

    Declaration
    public void CopyTo(T[] array, int arrayIndex)
    Parameters
    Type Name Description
    T[] array

    Destination array.

    int arrayIndex

    Zero based index in array at which copying begins.

    Exceptions
    Type Condition
    ArgumentNullException

    array is null.

    ArgumentException

    There is not enough space in array to accommodate all the items.

    ArgumentOutOfRangeException

    arrayIndex is less than 0.

    InvalidOperationException

    If the parent object of the InverseReferenceSet<T> has been deleted or abandoned.

    ObjectDisposedException

    If the parent object of the InverseReferenceSet<T> has been disposed.

    GetEnumerator()

    Returns an enumerator that iterates through InverseReferenceSet<T>.

    Declaration
    public IEnumerator<T> GetEnumerator()
    Returns
    Type Description
    IEnumerator<T>

    An enumerator.

    Remarks

    If InverseReferenceSet<T> changes, enumerator is invalidated. Any attempts to use it after that will throw an InvalidOperationException.

    Exceptions
    Type Condition
    InvalidOperationException

    If the parent object of the InverseReferenceSet<T> has been deleted or abandoned.

    ObjectDisposedException

    If the parent object of the InverseReferenceSet<T> has been disposed.

    ReleaseMemory()

    Releases the memory held by InverseReferenceSet<T>.

    Declaration
    public void ReleaseMemory()
    Remarks

    InverseReferenceSet<T> is lazy, it will not fetch inverse references until it needs to. Once you access inverse references, it will allocate an array to hold them. You can release this array by calling ReleaseMemory(). Once the array is released, if you once again access the InverseReferenceSet<T> it will allocate memory again.

    Remove(T)

    Remove an item from InverseReferenceSet<T>.

    Declaration
    public bool Remove(T item)
    Parameters
    Type Name Description
    T item

    Item to remove.

    Returns
    Type Description
    bool

    true if item was removed, otherwise if item is not found, it returns false.

    Remarks

    This is the same as removing the direct reference.

    Exceptions
    Type Condition
    ArgumentNullException

    item is null.

    InvalidOperationException

    If the parent object of the InverseReferenceSet<T> has been deleted or abandoned.

    ObjectDisposedException

    If the parent object of the InverseReferenceSet<T> has been disposed.

    Implements

    ICollection<T>
    IReadOnlyList<T>
    IReadOnlyCollection<T>
    IEnumerable<T>
    IEnumerable
    In this article
    © 2025 Copyright: VeloxDB