Table of Contents

Interface IConventionAnnotatable

Namespace
Microsoft.EntityFrameworkCore.Metadata
Assembly
Microsoft.EntityFrameworkCore.dll

A class that exposes annotations that can be modified. Annotations allow for arbitrary metadata to be stored on an object.

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

public interface IConventionAnnotatable : IReadOnlyAnnotatable
Inherited Members

Remarks

See Model building conventions for more information and examples.

Properties

Builder

Gets the builder that can be used to configure this object.

IConventionAnnotatableBuilder Builder { get; }

Property Value

IConventionAnnotatableBuilder

Exceptions

InvalidOperationException

If the object has been removed from the model.

IsInModel

Indicates whether this object is in a model, i.e. hasn't been removed from one.

bool IsInModel { get; }

Property Value

bool

Methods

AddAnnotation(string, object?, bool)

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

IConventionAnnotation AddAnnotation(string name, object? value, bool fromDataAnnotation = false)

Parameters

name string

The name of the annotation to be added.

value object

The value to be stored in the annotation.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

IConventionAnnotation

The newly added annotation.

AddAnnotations(IEnumerable<IConventionAnnotation>, bool)

Adds annotations to an object.

void AddAnnotations(IEnumerable<IConventionAnnotation> annotations, bool fromDataAnnotation = false)

Parameters

annotations IEnumerable<IConventionAnnotation>

The annotations to be added.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

FindAnnotation(string)

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

IConventionAnnotation? FindAnnotation(string name)

Parameters

name string

The name of the annotation to find.

Returns

IConventionAnnotation

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.

IConventionAnnotation GetAnnotation(string annotationName)

Parameters

annotationName string

The key of the annotation to find.

Returns

IConventionAnnotation

The annotation with the specified name.

GetAnnotations()

Gets all annotations on the current object.

IEnumerable<IConventionAnnotation> GetAnnotations()

Returns

IEnumerable<IConventionAnnotation>

RemoveAnnotation(string)

Removes the annotation with the given name from this object.

IConventionAnnotation? RemoveAnnotation(string name)

Parameters

name string

The name of the annotation to remove.

Returns

IConventionAnnotation

The annotation that was removed.

SetAnnotation(string, object?, bool)

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

IConventionAnnotation? SetAnnotation(string name, object? value, bool fromDataAnnotation = false)

Parameters

name string

The name of the annotation to be set.

value object

The value to be stored in the annotation.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

IConventionAnnotation

The new annotation.

SetOrRemoveAnnotation(string, object?, bool)

Sets the annotation stored under the given name. Overwrites the existing annotation if an annotation with the specified name already exists. Removes the existing annotation if null is supplied.

IConventionAnnotation? SetOrRemoveAnnotation(string name, object? value, bool fromDataAnnotation = false)

Parameters

name string

The name of the annotation to be added.

value object

The value to be stored in the annotation.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

IConventionAnnotation

The new annotation or null if it was removed.