Struct DbContextId
- Namespace
- Microsoft.EntityFrameworkCore
- Assembly
- Microsoft.EntityFrameworkCore.dll
A unique identifier for the context instance and pool lease, if any.
public readonly struct DbContextId
- Inherited Members
Remarks
This identifier is primarily intended as a correlation ID for logging and debugging such that it is easy to identify that multiple events are using the same or different context instances.
See DbContext lifetime, configuration, and initialization for more information and examples.
Constructors
DbContextId(Guid, int)
Creates a new DbContextId with the given InstanceId and lease number.
public DbContextId(Guid id, int lease)
Parameters
id
GuidA unique identifier for the DbContext being used.
lease
intA number indicating whether this is the first, second, third, etc. lease of this instance.
Properties
InstanceId
A unique identifier for the DbContext being used.
public Guid InstanceId { get; }
Property Value
Remarks
When context pooling is being used, then this ID must be combined with the Lease in order to get a unique ID for the effective instance being used.
Lease
A number that is incremented each time this particular DbContext instance is leased from the context pool.
public int Lease { get; }
Property Value
Remarks
Will be zero if context pooling is not being used.
Methods
Equals(DbContextId)
Compares this ID to another ID to see if they represent the same leased context.
public bool Equals(DbContextId other)
Parameters
other
DbContextIdThe other ID.
Returns
Equals(object?)
Compares this ID to another ID to see if they represent the same leased context.
public override bool Equals(object? obj)
Parameters
obj
objectThe other ID.
Returns
GetHashCode()
A hash code for this ID.
public override int GetHashCode()
Returns
- int
The hash code.
ToString()
Returns the instance ID and lease number.
public override string ToString()
Returns
- string
The instance ID and lease number.
Operators
operator ==(DbContextId, DbContextId)
Compares one ID to another ID to see if they represent the same leased context.
public static bool operator ==(DbContextId left, DbContextId right)
Parameters
left
DbContextIdThe first ID.
right
DbContextIdThe second ID.
Returns
operator !=(DbContextId, DbContextId)
Compares one ID to another ID to see if they represent different leased contexts.
public static bool operator !=(DbContextId left, DbContextId right)
Parameters
left
DbContextIdThe first ID.
right
DbContextIdThe second ID.