Table of Contents

Class HasManyAttribute

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

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

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

Examples

public class Author : Identifiable
{
    [HasMany]
    public ISet<Article> Articles { get; set; }
}

Constructors

HasManyAttribute()

public HasManyAttribute()

Properties

Capabilities

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

public HasManyCapabilities Capabilities { get; set; }

Property Value

HasManyCapabilities

Examples

public class Book : Identifiable<long>
{
    [HasMany(Capabilities = HasManyCapabilities.AllowView | HasManyCapabilities.AllowInclude)]
    public ISet<Chapter> Chapters { get; set; } = new HashSet<Chapter>();
}

Methods

AddValue(object, IIdentifiable)

Adds a resource to this to-many relationship 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 void AddValue(object resource, IIdentifiable resourceToAdd)

Parameters

resource object
resourceToAdd IIdentifiable

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