Table of Contents

Class AnnotatableBase

Namespace
Microsoft.EntityFrameworkCore.Infrastructure
Assembly
Microsoft.EntityFrameworkCore.dll

Base class for types that support reading and writing annotations.

This type is typically used by database providers (and other extensions). It is generally not used in application code.

public class AnnotatableBase : IAnnotatable, IReadOnlyAnnotatable
Inheritance
AnnotatableBase
Implements
Derived
Inherited Members

Remarks

See Implementation of database providers and extensions for more information and examples.

Constructors

AnnotatableBase()

public AnnotatableBase()

Properties

IsReadOnly

Indicates whether the current object is read-only.

public virtual bool IsReadOnly { get; }

Property Value

bool

Remarks

Annotations cannot be changed when the object is read-only. Runtime annotations cannot be changed when the object is not read-only.

this[string]

Gets the value annotation with the given name, returning null if it does not exist.

public virtual object? this[string name] { get; set; }

Parameters

name string

The key of the annotation to find.

Property Value

object

The value of the existing annotation if an annotation with the specified name already exists. Otherwise, null.

Methods

AddAnnotation(string, Annotation)

Adds an annotation to this object. Throws if an annotation with the specified name already exists.

protected virtual Annotation AddAnnotation(string name, Annotation annotation)

Parameters

name string

The key of the annotation to be added.

annotation Annotation

The annotation to be added.

Returns

Annotation

The added annotation.

AddAnnotation(string, object?)

Adds an annotation to this object. Throws if an annotation with the specified name already exists.

public virtual Annotation AddAnnotation(string name, object? value)

Parameters

name string

The key of the annotation to be added.

value object

The value to be stored in the annotation.

Returns

Annotation

The newly added annotation.

AddAnnotations(IEnumerable<IAnnotation>)

Adds annotations to this object.

public virtual void AddAnnotations(IEnumerable<IAnnotation> annotations)

Parameters

annotations IEnumerable<IAnnotation>

The annotations to be added.

AddAnnotations(IReadOnlyDictionary<string, object?>)

Adds annotations to this object.

public virtual void AddAnnotations(IReadOnlyDictionary<string, object?> annotations)

Parameters

annotations IReadOnlyDictionary<string, object>

The annotations to be added.

AddRuntimeAnnotation(string, Annotation)

Adds a runtime annotation to this object. Throws if an annotation with the specified name already exists.

protected virtual Annotation AddRuntimeAnnotation(string name, Annotation annotation)

Parameters

name string

The key of the annotation to be added.

annotation Annotation

The annotation to be added.

Returns

Annotation

The added annotation.

AddRuntimeAnnotation(string, object?)

Adds a runtime annotation to this object. Throws if an annotation with the specified name already exists.

public virtual Annotation AddRuntimeAnnotation(string name, object? value)

Parameters

name string

The key of the annotation to be added.

value object

The value to be stored in the annotation.

Returns

Annotation

The newly added annotation.

AddRuntimeAnnotations(IEnumerable<Annotation>)

Adds runtime annotations to this object.

public virtual void AddRuntimeAnnotations(IEnumerable<Annotation> annotations)

Parameters

annotations IEnumerable<Annotation>

The annotations to be added.

AddRuntimeAnnotations(IReadOnlyDictionary<string, object?>)

Adds runtime annotations to this object.

public virtual void AddRuntimeAnnotations(IReadOnlyDictionary<string, object?> annotations)

Parameters

annotations IReadOnlyDictionary<string, object>

The annotations to be added.

CreateAnnotation(string, object?)

Creates a new annotation.

protected virtual Annotation CreateAnnotation(string name, object? value)

Parameters

name string

The key of the annotation.

value object

The value to be stored in the annotation.

Returns

Annotation

The newly created annotation.

CreateRuntimeAnnotation(string, object?)

Creates a new runtime annotation.

protected virtual Annotation CreateRuntimeAnnotation(string name, object? value)

Parameters

name string

The key of the annotation.

value object

The value to be stored in the annotation.

Returns

Annotation

The newly created annotation.

EnsureMutable()

Throws if the model is read-only.

protected virtual void EnsureMutable()

EnsureReadOnly()

Throws if the model is not read-only.

protected virtual void EnsureReadOnly()

FindAnnotation(string)

Gets the annotation with the given name, returning null if it does not exist.

public virtual Annotation? FindAnnotation(string name)

Parameters

name string

The key of the annotation to find.

Returns

Annotation

The existing annotation if an annotation with the specified name already exists. Otherwise, null.

FindRuntimeAnnotation(string)

Gets the runtime annotation with the given name, returning null if it does not exist.

public virtual Annotation? FindRuntimeAnnotation(string name)

Parameters

name string

The key of the annotation to find.

Returns

Annotation

The existing annotation if an annotation with the specified name already exists. Otherwise, null.

GetAnnotation(string)

Gets the annotation with the given name, throwing if it does not exist.

public virtual Annotation GetAnnotation(string annotationName)

Parameters

annotationName string

The key of the annotation to find.

Returns

Annotation

The annotation with the specified name.

GetAnnotations()

Gets all annotations on the current object.

public virtual IEnumerable<Annotation> GetAnnotations()

Returns

IEnumerable<Annotation>

GetOrAddRuntimeAnnotationValue<TValue, TArg>(string, Func<TArg?, TValue>, TArg?)

Gets the value of the runtime annotation with the given name, adding it if one does not exist.

public virtual TValue GetOrAddRuntimeAnnotationValue<TValue, TArg>(string name, Func<TArg?, TValue> valueFactory, TArg? factoryArgument)

Parameters

name string

The name of the annotation.

valueFactory Func<TArg, TValue>

The factory used to create the value if the annotation doesn't exist.

factoryArgument TArg

An argument for the factory method.

Returns

TValue

The value of the existing runtime annotation if an annotation with the specified name already exists. Otherwise a newly created value.

Type Parameters

TValue
TArg

GetRuntimeAnnotations()

Gets all runtime annotations on the current object.

public virtual IEnumerable<Annotation> GetRuntimeAnnotations()

Returns

IEnumerable<Annotation>

OnAnnotationSet(string, Annotation?, Annotation?)

Called when an annotation was set or removed.

protected virtual Annotation? OnAnnotationSet(string name, Annotation? annotation, Annotation? oldAnnotation)

Parameters

name string

The key of the set annotation.

annotation Annotation

The annotation set.

oldAnnotation Annotation

The old annotation.

Returns

Annotation

The annotation that was set.

RemoveAnnotation(string)

Removes the given annotation from this object.

public virtual Annotation? RemoveAnnotation(string name)

Parameters

name string

The annotation to remove.

Returns

Annotation

The annotation that was removed.

RemoveRuntimeAnnotation(string)

Removes the given runtime annotation from this object.

public virtual Annotation? RemoveRuntimeAnnotation(string name)

Parameters

name string

The annotation to remove.

Returns

Annotation

The annotation that was removed.

SetAnnotation(string, Annotation, Annotation?)

Sets the annotation stored under the given key. Overwrites the existing annotation if an annotation with the specified name already exists.

protected virtual Annotation? SetAnnotation(string name, Annotation annotation, Annotation? oldAnnotation)

Parameters

name string

The key of the annotation to be added.

annotation Annotation

The annotation to be set.

oldAnnotation Annotation

The annotation being replaced.

Returns

Annotation

The annotation that was set.

SetAnnotation(string, object?)

Sets the annotation stored under the given key. Overwrites the existing annotation if an annotation with the specified name already exists.

public virtual void SetAnnotation(string name, object? value)

Parameters

name string

The key of the annotation to be added.

value object

The value to be stored in the annotation.

SetRuntimeAnnotation(string, Annotation, Annotation?)

Sets the runtime annotation stored under the given key. Overwrites the existing annotation if an annotation with the specified name already exists.

protected virtual Annotation SetRuntimeAnnotation(string name, Annotation annotation, Annotation? oldAnnotation)

Parameters

name string

The key of the annotation to be added.

annotation Annotation

The annotation to be set.

oldAnnotation Annotation

The annotation being replaced.

Returns

Annotation

The annotation that was set.

SetRuntimeAnnotation(string, object?)

Sets the runtime annotation stored under the given key. Overwrites the existing annotation if an annotation with the specified name already exists.

public virtual Annotation SetRuntimeAnnotation(string name, object? value)

Parameters

name string

The key of the annotation to be added.

value object

The value to be stored in the annotation.

Returns

Annotation