Current User Name Property

View Entity Current User Name Property Configuration Options

Tracking Current User

The AddCurrentUserName method defines a backend-managed property that automatically stores the username of the person who created or updated a record.

This is useful when you need to track who performed certain actions, such as:

  • Who created the record (CreatedBy)
  • Who last modified the record (ModifiedBy)

You can configure it like this:


designer.Properties.AddCurrentUserName("CreatedBy", BkAutomaticUpdateOn.OnlyCreate);
designer.Properties.AddCurrentUserName("ModifiedBy", BkAutomaticUpdateOn.OnlyUpdate);

In these examples:

  • CreatedBy will be set once when the record is first created.
  • ModifiedBy will be updated each time the record is edited.

⚠️ Authentication Is Required

When you use AddCurrentUserName, the framework requires that a user is authenticated at runtime. If this property is present on an entity and no user is logged in, the entity becomes non-editable.

This is a safety mechanism to ensure that user-related audit fields are never left blank or filled with anonymous data. Therefore, authentication is mandatory when using CreatedBy or ModifiedBy.

Behavior Summary

  • The user name is set automatically — no editor is rendered in forms.
  • The field can be displayed in the UI (e.g., grids, details, or reports).
  • The value is based on the current logged-in user’s identity.
  • Trying to save or update without an authenticated user will result in failure.

publicpartialclassEmployee:IBkEntity<Employee,ApplicationDbContext>

{

    publicvoidBkConfiguration(IBkEntityDesigner<Employee,ApplicationDbContext>designer)

    {

        designer.Properties.AddCurrentUserName("CreatedBy",BkAutomaticUpdateOn.OnlyCreate);

        designer.Properties.AddCurrentUserName("ModifiedBy",BkAutomaticUpdateOn.OnlyUpdate);

// ... other properties    }

}

An unhandled error has occurred. Reload 🗙