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
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
stringThe 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
stringThe key of the annotation to be added.
annotation
AnnotationThe 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
stringThe key of the annotation to be added.
value
objectThe 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
stringThe key of the annotation to be added.
annotation
AnnotationThe 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
stringThe key of the annotation to be added.
value
objectThe 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
Returns
- Annotation
The newly created annotation.
CreateRuntimeAnnotation(string, object?)
Creates a new runtime annotation.
protected virtual Annotation CreateRuntimeAnnotation(string name, object? value)
Parameters
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
stringThe 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
stringThe 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
stringThe 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
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
stringThe name of the annotation.
valueFactory
Func<TArg, TValue>The factory used to create the value if the annotation doesn't exist.
factoryArgument
TArgAn 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
OnAnnotationSet(string, Annotation?, Annotation?)
Called when an annotation was set or removed.
protected virtual Annotation? OnAnnotationSet(string name, Annotation? annotation, Annotation? oldAnnotation)
Parameters
name
stringThe key of the set annotation.
annotation
AnnotationThe annotation set.
oldAnnotation
AnnotationThe 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
stringThe 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
stringThe 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
stringThe key of the annotation to be added.
annotation
AnnotationThe annotation to be set.
oldAnnotation
AnnotationThe 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
stringThe key of the annotation to be added.
value
objectThe 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
stringThe key of the annotation to be added.
annotation
AnnotationThe annotation to be set.
oldAnnotation
AnnotationThe 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
stringThe key of the annotation to be added.
value
objectThe value to be stored in the annotation.