Partilhar via


ValueComparer<T> Class

Definition

Specifies custom value snapshotting and comparison for CLR types that cannot be compared with Equals(Object, Object) and/or need a deep copy when taking a snapshot. For example, arrays of primitive types will require both if mutation is to be detected.

public class ValueComparer<T> : Microsoft.EntityFrameworkCore.ChangeTracking.ValueComparer, System.Collections.Generic.IEqualityComparer<T>
type ValueComparer<'T> = class
    inherit ValueComparer
    interface IEqualityComparer<'T>
Public Class ValueComparer(Of T)
Inherits ValueComparer
Implements IEqualityComparer(Of T)

Type Parameters

T

The type.

Inheritance
ValueComparer<T>
Derived
Implements

Remarks

Snapshotting is the process of creating a copy of the value into a snapshot so it can later be compared to determine if it has changed. For some types, such as collections, this needs to be a deep copy of the collection rather than just a shallow copy of the reference.

See EF Core value comparers for more information and examples.

Constructors

ValueComparer<T>(Boolean)

Creates a new ValueComparer<T> with a default comparison expression and a shallow copy for the snapshot.

ValueComparer<T>(Expression<Func<T,T,Boolean>>, Expression<Func<T,Int32>>, Expression<Func<T,T>>)

Creates a new ValueComparer<T> with the given comparison and snapshotting expressions.

ValueComparer<T>(Expression<Func<T,T,Boolean>>, Expression<Func<T,Int32>>)

Creates a new ValueComparer<T> with the given comparison expression. A shallow copy will be used for the snapshot.

Properties

ConstructorExpression

The expression representing construction of this object.

ConstructorExpression

The expression representing construction of this object.

(Inherited from ValueComparer)
EqualsExpression

The comparison expression.

HashCodeExpression

The hash code expression.

ObjectEqualsExpression

The object comparison expression.

ObjectEqualsExpression

The object comparison expression.

(Inherited from ValueComparer)
SnapshotExpression

The snapshot expression.

Type

The type.

Methods

CreateDefaultEqualsExpression()

Creates an expression for equality.

CreateDefaultHashCodeExpression(Boolean)

Creates an expression for generating a hash code.

CreateDefaultSnapshotExpression(Boolean)

Creates an expression for creating a snapshot of a value.

Equals(Object, Object)

Compares the two instances to determine if they are equal.

Equals(T, T)

Compares the two instances to determine if they are equal.

ExtractEqualsBody(Expression, Expression)

Takes EqualsExpression and replaces the two parameters with the given expressions, returning the transformed body.

(Inherited from ValueComparer)
ExtractHashCodeBody(Expression)

Takes the HashCodeExpression and replaces the parameter with the given expression, returning the transformed body.

(Inherited from ValueComparer)
ExtractSnapshotBody(Expression)

Takes the SnapshotExpression and replaces the parameter with the given expression, returning the transformed body.

(Inherited from ValueComparer)
GetHashCode(Object)

Returns the hash code for the given instance.

GetHashCode(T)

Returns the hash code for the given instance.

Snapshot(Object)

Creates a snapshot of the given instance.

Snapshot(T)

Creates a snapshot of the given instance.

Extension Methods

IsDefault(ValueComparer)

Returns true if the given ValueComparer is a default EF Core implementation.

Applies to