Useful extensions

For (SmartDb)Context and DbSet

DbContext extensions

chevron-rightOpenConnection(Async)hashtag

Opens and retains connection until end of scope. Call this method in long running processes to gain slightly faster database interaction.

chevron-rightFindTrackedhashtag

Tries to locate an already loaded and tracked entity in the local state manager.

chevron-rightHasChangeshashtag

Checks whether at least one entity in the change tracker is in Added, Deleted or Modified state.

chevron-rightTryUpdatehashtag

Sets the state of an entity to Modified if it is detached.

chevron-rightTryChangeStatehashtag

Changes the state of an entity object when requested state differs.

chevron-rightTryGetModifiedPropertyhashtag

Determines whether an entity property has changed since it was attached.

chevron-rightGetModifiedPropertieshashtag

Gets a list of modified properties for a given entity.

chevron-rightReloadEntity(Async)hashtag

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.

chevron-rightDetachEntityhashtag

Detaches a single entity from the current context if it is attached.

chevron-rightDetachEntitieshashtag

Detaches many entities from the current context.

chevron-rightIsCollectionLoadedhashtag

Checks whether a collection type navigation property has already been loaded for a given entity (either eagerly or lazily).

chevron-rightIsReferenceLoadedhashtag

Checks whether a reference type navigation property has already been loaded for a given entity (either eagerly or lazily).

chevron-rightLoadCollectionAsynchashtag

Loads entities referenced by a collection navigation property from database, unless data is already loaded.

chevron-rightLoadReferenceAsynchashtag

Loads an entity referenced by a navigation property from database, unless data is already loaded.

DbSet extensions

chevron-rightGetDbContexthashtag

Resolves the DbContext instance from which a given DbSet was obtained.

chevron-rightFindById(Async)hashtag

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.

chevron-rightGetMany(Async)hashtag

Loads many entities from database sorted by the given id sequence. Sort is applied in-memory.

chevron-rightDeleteAll(Async)hashtag

Truncates the table for a given entity type.

Last updated

Was this helpful?