Skip to main content

ChangeTracker

Struct ChangeTracker 

Source
pub struct ChangeTracker { /* private fields */ }
Expand description

Tracks changes to entities within a DbContext.

Implementations§

Source§

impl ChangeTracker

Source

pub fn new() -> Self

Source

pub fn track_entity_with_snapshot( &mut self, type_id: TypeId, type_name: &str, state: EntityState, snapshot: HashMap<String, String>, ) -> u64

Takes a snapshot of the entity’s current properties and begins tracking.

The snapshotter closure should return a map of property-name �?string serialization of the property’s current value.

Source

pub fn track_entity( &mut self, type_id: TypeId, type_name: &str, state: EntityState, ) -> u64

Begins tracking an entity without taking a snapshot (used for Added entities that have no pre-existing state).

Source

pub fn detect_changes_with_properties( &mut self, current_properties: &[(u64, HashMap<String, String>)], )

Compares current property values (provided by the caller) against the stored snapshots. Any property whose value differs is marked as modified, and the entity transitions to EntityState::Modified.

Source

pub fn update_snapshot( &mut self, entry_id: u64, properties: HashMap<String, String>, )

Marks the property snapshot for the given entry as updated. Used after a successful SaveChanges to update the “original” values.

Source

pub fn has_changes(&self) -> bool

Returns whether any tracked entity has changes pending.

Source

pub fn clear(&mut self)

Clears all tracked entities.

Source

pub fn entries(&self) -> Vec<EntityEntry>

Returns an iterator over tracked entry views.

Source

pub fn count_by_state(&self, state: EntityState) -> usize

Returns count of entities in a given state.

Source

pub fn entries_by_state(&self, state: EntityState) -> Vec<EntityEntry>

Returns entities grouped by their state.

Source

pub fn accept_all_changes(&mut self)

After successful SaveChanges:

  • Added �?Unchanged (save snapshot)
  • Modified �?Unchanged (save current as new snapshot)
  • Deleted �?Detached (removed from tracker)
Source

pub fn reject_all_changes(&mut self)

Reverts all pending changes (detached state reverted).

Source

pub fn detach(&mut self, entry_id: u64)

Detaches a specific entry by ID.

Source

pub fn is_auto_detect_changes_enabled(&self) -> bool

Source

pub fn set_auto_detect_changes(&mut self, enabled: bool)

Trait Implementations§

Source§

impl Debug for ChangeTracker

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ChangeTracker

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.