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.
Implements
Namespace: VeloxDB.ObjectInterface
Assembly: vlxdb.dll
Syntax
public sealed class InverseReferenceSet<T> : InverseReferenceSet, ICollection<T>, IEnumerable<T>, IEnumerable, IReadOnlyList<T>, IReadOnlyCollection<T> 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 |
---|---|
System.Int32 |
Overrides
IsReadOnly
Gets if the InverseReferenceSet<T> is Readonly. Always returns false.
Declaration
public bool IsReadOnly { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Item[Int32]
Index accessor.
Declaration
public T this[int index] { get; }
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | Index of the item to get. |
Property Value
Type | Description |
---|---|
T | Requested item. |
Exceptions
Type | Condition |
---|---|
System.IndexOutOfRangeException | If |
System.InvalidOperationException | If the parent object of the DatabaseArray<T> has been deleted or abandoned. |
System.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 |
---|---|
System.ArgumentNullException | If |
System.InvalidOperationException | If the parent object of the InverseReferenceSet<T> has been deleted or abandoned. |
System.ObjectDisposedException | If the parent object of the InverseReferenceSet<T> has been disposed. |
Clear()
Clears all references.
Declaration
public void Clear()
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | If the parent object of the InverseReferenceSet<T> has been deleted or abandoned. |
System.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 |
---|---|
System.Boolean |
|
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | If |
System.InvalidOperationException | If the parent object of the InverseReferenceSet<T> has been deleted or abandoned. |
System.ObjectDisposedException | If the parent object of the InverseReferenceSet<T> has been disposed. |
CopyTo(T[], Int32)
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. |
System.Int32 | arrayIndex | Zero based index in |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.ArgumentException | There is not enough space in |
System.ArgumentOutOfRangeException |
|
System.InvalidOperationException | If the parent object of the InverseReferenceSet<T> has been deleted or abandoned. |
System.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 |
---|---|
System.Collections.Generic.IEnumerator<T> | An enumerator. |
Remarks
If InverseReferenceSet<T> changes, enumerator is invalidated. Any attempts to use it after that will throw an System.InvalidOperationException.
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | If the parent object of the InverseReferenceSet<T> has been deleted or abandoned. |
System.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 |
---|---|
System.Boolean |
|
Remarks
This is the same as removing the direct reference.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
System.InvalidOperationException | If the parent object of the InverseReferenceSet<T> has been deleted or abandoned. |
System.ObjectDisposedException | If the parent object of the InverseReferenceSet<T> has been disposed. |