Table of Contents

Class HasOneAttribute

Namespace
JsonApiDotNetCore.Resources.Annotations
Assembly
JsonApiDotNetCore.Annotations.dll

Used to expose a property on a resource class as a JSON:API to-one relationship (https://jsonapi.org/format/#document-resource-object-relationships).

[PublicAPI]
[AttributeUsage(AttributeTargets.Property)]
public sealed class HasOneAttribute : RelationshipAttribute
Inheritance
HasOneAttribute
Inherited Members

Examples

public class Article : Identifiable
{
    [HasOne]
    public Author Author { get; set; }
}

Constructors

HasOneAttribute()

public HasOneAttribute()

Properties

Capabilities

The set of allowed capabilities on this to-one relationship. When not explicitly set, the configured default set of capabilities is used.

public HasOneCapabilities Capabilities { get; set; }

Property Value

HasOneCapabilities

Examples

public class Book : Identifiable<long>
{
    [HasOne(Capabilities = HasOneCapabilities.AllowView | HasOneCapabilities.AllowInclude)]
    public Person? Author { get; set; }
}

Methods

Equals(object?)

Returns a value that indicates whether this instance is equal to a specified object.

public override bool Equals(object? obj)

Parameters

obj object

An object to compare with this instance or null.

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.

SetValue(object, object?)

Sets the value of this field on the specified resource instance. Throws if the property is read-only or if the field does not belong to the specified resource instance.

public override void SetValue(object resource, object? newValue)

Parameters

resource object
newValue object