Class RelationshipAttribute
- Namespace
- JsonApiDotNetCore.Resources.Annotations
- Assembly
- JsonApiDotNetCore.Annotations.dll
Used to expose a property on a resource class as a JSON:API relationship (https://jsonapi.org/format/#document-resource-object-relationships).
[PublicAPI]
public abstract class RelationshipAttribute : ResourceFieldAttribute
- Inheritance
-
RelationshipAttribute
- Derived
- Inherited Members
Properties
CanInclude
Whether or not this relationship can be included using the include
query string parameter. This is true
by default.
[Obsolete("Use AllowInclude in Capabilities instead.")]
public bool CanInclude { get; set; }
Property Value
Remarks
When explicitly set, this value takes precedence over Capabilities for backwards-compatibility. Capabilities are adjusted accordingly when building the resource graph.
InverseNavigationProperty
The PropertyInfo of the Entity Framework Core inverse navigation, which may or may not exist. Even if it exists, it may not be exposed as a JSON:API relationship.
public PropertyInfo? InverseNavigationProperty { get; set; }
Property Value
Examples
public class Article : Identifiable
{
[HasOne] // InverseNavigationProperty: Person.Articles
public Person Owner { get; set; }
}
public class Person : Identifiable
{
[HasMany] // InverseNavigationProperty: Article.Owner
public ICollection<Article> Articles { get; set; }
}
LeftType
The containing resource type in which this relationship is declared. Identical to Type.
public ResourceType LeftType { get; }
Property Value
Links
Configures which links to write in the relationship-level links object for this relationship. Defaults to NotConfigured, which falls back to RelationshipLinks and then falls back to RelationshipLinks in global options.
public LinkTypes Links { get; set; }
Property Value
RightType
The resource type this relationship points to. In the case of a HasManyAttribute relationship, this value will be the collection element type.
public ResourceType RightType { get; }
Property Value
Examples
public ISet<Tag> Tags { get; set; } // RightType: Tag
Methods
Equals(object?)
Returns a value that indicates whether this instance is equal to a specified object.
public override bool Equals(object? obj)
Parameters
Returns
- bool
true if
obj
and this instance are of the same type and have identical field values; otherwise, false.
GetHashCode()
Returns the hash code for this instance.
public override int GetHashCode()
Returns
- int
A 32-bit signed integer hash code.