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 InverseReferencesAttribute
Specifies that the property represents an inverse reference.
Inheritance
Namespace: VeloxDB.ObjectInterface
Assembly: vlxdb.dll
Syntax
public sealed class InverseReferencesAttribute : Attribute
Remarks
When you define a reference between two classes using DatabaseReferenceAttribute, you can also define an inverse reference on the target class. Inverse reference enables you to navigate a reference in reverse direction. To declare an inverse reference declare a property of InverseReferenceSet<T> type and mark it with InverseReferencesAttribute.
Note
TrackInverseReferences must be set to true for the reference if you want to use inverse references.
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 inverse reference.
[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;
}
Constructors
InverseReferencesAttribute(String)
Declaration
public InverseReferencesAttribute(string propertyName)
Parameters
Type | Name | Description |
---|---|---|
System.String | propertyName | Name of the property that represent's the direct reference. |
Properties
PropertyName
Get's the name of the direct reference property.
Declaration
public string PropertyName { get; }
Property Value
Type | Description |
---|---|
System.String |