Useful extensions
For (SmartDb)Context and DbSet
DbContext extensions
OpenConnection(Async)
Opens and retains connection until end of scope. Call this method in long running processes to gain slightly faster database interaction.
HasChanges
Checks whether at least one entity in the change tracker is in Added
, Deleted
or Modified
state.
ReloadEntity(Async)
Reloads the entity from the database overwriting any property values with values from the database. The entity will be in the Unchanged
state after calling this method.
IsCollectionLoaded
Checks whether a collection type navigation property has already been loaded for a given entity (either eagerly or lazily).
IsReferenceLoaded
Checks whether a reference type navigation property has already been loaded for a given entity (either eagerly or lazily).
LoadCollectionAsync
Loads entities referenced by a collection navigation property from database, unless data is already loaded.
LoadReferenceAsync
Loads an entity referenced by a navigation property from database, unless data is already loaded.
DbSet extensions
FindById(Async)
Finds an entity with a given id. If an entity with the given id is being tracked by the context, it is returned immediately without making a request to the database. Otherwise, a query is made to the database for an entity with the given id and this entity, if found, is returned. If no entity is found, then null
is returned. If the tracked
parameter is set to true
, the entity is also attached to the context, so that subsequent calls can return the tracked entity without a database roundtrip.
Last updated
Was this helpful?