Table of Contents

Class EntityReferenceBase<T>

Namespace
The.Relationships
Assembly
Instagile.dll

Base class for generated reference navigation types: a single-step EntityPathBase<T> backed by the underlying EntityReferenceProperty<T>, or a detached value created by the generated implicit conversion for assignment.

public abstract class EntityReferenceBase<T> : EntityPathBase<T>, IEntityReference<T>, IEntityPath<T>, IEntityPath, ILazy<T?>, ILazy where T : IEntity<T>

Type Parameters

T
Inheritance
EntityReferenceBase<T>
Implements
Inherited Members

Constructors

EntityReferenceBase(EntityReferenceProperty<T>)

protected EntityReferenceBase(EntityReferenceProperty<T> property)

Parameters

property EntityReferenceProperty<T>

EntityReferenceBase(T?)

Creates a detached reference carrying an assignment value.

protected EntityReferenceBase(T? value)

Parameters

value T

Properties

HasValue

Whether the foreign key is set. Distinct from IsPresent; never performs I/O.

[MemberNotNullWhen(true, "ID")]
public bool HasValue { get; }

Property Value

bool

ID

Gets or sets the referenced entity by ID, without loading anything.

public Guid? ID { get; set; }

Property Value

Guid?

Property

The property object backing this reference.

protected EntityReferenceProperty<T> Property { get; }

Property Value

EntityReferenceProperty<T>

Exceptions

InvalidOperationException

Thrown for a detached reference, which has no backing property.

Methods

AsLoaded()

Asserts that the path is loaded and returns the entity at its end (or null when a reference along the path is genuinely null); never performs I/O. This also backs the generated explicit conversion operators and query-only members, which exist for use in expression trees or to be executed by query providers against prefetched data.

public override T? AsLoaded()

Returns

T

Exceptions

InvalidOperationException

Thrown if any reference along the path is unloaded, naming the first that is.

InvalidOperationException

Thrown if the target is unloaded, naming the relationship and foreign key.

Equals(object?)

Determines whether the specified object is equal to the current object.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current object.

Returns

bool

true if the specified object is equal to the current object; otherwise, false.

GetHashCode()

Serves as the default hash function.

public override int GetHashCode()

Returns

int

A hash code for the current object.

LoadCachedAsync(RequestOptions?, RelationshipPath[], CancellationToken?)

Paths through more than one reference do not use the entity cache; references override this to use it.

public override Task<T?> LoadCachedAsync(RequestOptions? options, RelationshipPath[] includes, CancellationToken? cancellationToken = null)

Parameters

options RequestOptions
includes RelationshipPath[]
cancellationToken CancellationToken?

Returns

Task<T>

ToString()

The relationship and foreign key ("3: Foo.Bar: {ID}", or "null" for no target), whether or not the target is loaded; never the target's own text.

public override string ToString()

Returns

string

Events

ValueChanged

Raised when the reference is changed to point at a different entity.

public event EventHandler? ValueChanged

Event Type

EventHandler

Operators

operator ==(EntityReferenceBase<T>?, T?)

Whether the reference refers to the entity, by foreign key and without loading; a null entity matches a null reference.

public static bool operator ==(EntityReferenceBase<T>? left, T? right)

Parameters

left EntityReferenceBase<T>
right T

Returns

bool

operator ==(T?, EntityReferenceBase<T>?)

Whether the reference refers to the entity, by foreign key and without loading; a null entity matches a null reference.

public static bool operator ==(T? left, EntityReferenceBase<T>? right)

Parameters

left T
right EntityReferenceBase<T>

Returns

bool

operator !=(EntityReferenceBase<T>?, T?)

public static bool operator !=(EntityReferenceBase<T>? left, T? right)

Parameters

left EntityReferenceBase<T>
right T

Returns

bool

operator !=(T?, EntityReferenceBase<T>?)

public static bool operator !=(T? left, EntityReferenceBase<T>? right)

Parameters

left T
right EntityReferenceBase<T>

Returns

bool