DbFieldCache

A class that is being used to retrieve the cached database fields of the class or data entity.

A cacher class for database table fields. It provides a second caching layer for field extraction, allowing the library to reuse previously extracted database fields for faster execution.

Methods

Below is the list of methods.

Name Description
Flush Allows you to flush the caches.
Get Returns the list of DbField objects.

Usability

Call the Get() method by passing the literal table name:

using (var connection = new SqlConnection(connectionString))
{
    var dbFields = DbFieldCache.Get("[dbo].[Person]", connection, transaction: null);
    // Use the 'dbFields' here
}

Or use ClassMappedNameCache to resolve the mapped entity name:

using (var connection = new SqlConnection(connectionString))
{
    var dbFields = DbFieldCache.Get(ClassMappedNameCache.Get<Person>(), connection, transaction: null);
    // Use the 'dbFields' here
}

The Get() method requires a DbConnection. If the cache is empty, fields are extracted from the database, cached, and returned to the caller.