IPowerPortalsProService

The IPowerPortalsProService interface provides methods for performing CRUD operations, executing queries, managing relationships, and retrieving metadata from Dataverse. It is the primary service for server-side data access in PowerPortalsPro.

Note

In most cases you do not need to call IPowerPortalsProService directly. The RecordContext, MainContext, and grid components handle data operations automatically. Use this service for custom logic that falls outside the standard component workflow.

Server and Client Implementations

IPowerPortalsProService ships with two implementations registered automatically by the framework — your component code is identical against both, and the runtime injects whichever one matches the active render context:

  • Server implementation (PowerPortalsPro.Web.Server, registered by AddPowerPortalsProWebServer) — runs in-process, talks to Dataverse directly through IOrganizationService, and applies your ITablePermissionHandler / ITableRecordPermissionHandler interceptors before any read or write. Selected when the page renders under InteractiveServerRenderMode or static SSR.
  • Client implementation (PowerPortalsPro.Web.Client, registered by AddPowerPortalsProWebClient) — runs in the browser under WebAssembly, has no Dataverse SDK at all, and instead JSON-serializes each call out to the corresponding server-side HTTP endpoint (/api/table/{name}, /api/retrieveMultiple, etc.). Permission handlers still apply because the request lands back on the server's endpoint. See the HTTP Endpoints page for the wire format and the routes the client implementation calls.

Because the contract is identical, the same component works under any interactivity mode (Server, WebAssembly, or Auto). Code that calls _powerPortalsProService.RetrieveRecordAsync(...) in a Server-rendered page does an in-process Dataverse call; the same line in a WASM-rendered page issues an HTTP request — no branching required.

Injecting the Service

Inject IPowerPortalsProService into any Blazor component or service via constructor or property injection.

[Inject]
private IPowerPortalsProService _powerPortalsProService { get; set; } = null!;

Retrieving a Record

Use RetrieveRecordAsync to fetch a single record by table name and ID. Optionally specify which columns to return; if omitted, all columns are returned.

// Retrieve all columns
var account = await _powerPortalsProService.RetrieveRecordAsync("account", accountId);

// Retrieve specific columns only
var account = await _powerPortalsProService.RetrieveRecordAsync("account", accountId,
    new[] { "name", "telephone1", "address1_city" });

Querying Multiple Records

Use RetrieveRecordsAsync with a FetchXML query string to retrieve multiple records with filtering, sorting, and linked entity support.

var fetchXml = @"<fetch>
    <entity name='contact'>
        <attribute name='fullname' />
        <attribute name='emailaddress1' />
        <filter>
            <condition attribute='parentcustomerid' operator='eq' value='...' />
        </filter>
        <order attribute='fullname' />
    </entity>
</fetch>";

var response = await _powerPortalsProService.RetrieveRecordsAsync(fetchXml);
foreach (var record in response.TableRecords)
{
    // Process each record
}

Creating a Record

Use CreateRecordAsync to create a new record in Dataverse. The response contains the ID of the newly created record.

var newContact = new TableRecord { TableName = "contact" };
newContact["firstname"] = new StringValue("John");
newContact["lastname"] = new StringValue("Doe");

var response = await _powerPortalsProService.CreateRecordAsync(newContact);
var newRecordId = response.Id;

Updating a Record

Use UpdateRecordAsync to update an existing record. Only the properties set on the TableRecord are sent to Dataverse.

var recordToUpdate = new TableRecord
{
    TableName = "contact",
    Id = contactId
};
recordToUpdate["telephone1"] = new StringValue("555-1234");

await _powerPortalsProService.UpdateRecordAsync(recordToUpdate);

Deleting a Record

Use DeleteRecordAsync to delete a record by table name and ID.

await _powerPortalsProService.DeleteRecordAsync("contact", contactId);

Associating Records

Use AssociateAsync and DisassociateAsync to manage many-to-many relationships between records.

// Associate
var account = new TableRecordReference("account", accountId);
var regions = new List<TableRecordReference>
{
    new TableRecordReference("ppp_region", regionId1),
    new TableRecordReference("ppp_region", regionId2),
};
await _powerPortalsProService.AssociateAsync(account, "ppp_Account_ppp_Region_ppp_Region", regions);

// Disassociate
await _powerPortalsProService.DisassociateAsync(account, "ppp_Account_ppp_Region_ppp_Region", regions);

Executing Requests

Use ExecuteAsync for a single request or ExecuteMultipleAsync to execute multiple requests in a single database transaction. If any request in a transactional batch fails, all changes are rolled back.

// Execute multiple requests in a single transaction
var requests = new List<OrganizationRequest>
{
    new CreateRequest(contact),
    new UpdateRequest(account),
};

var responses = await _powerPortalsProService.ExecuteMultipleAsync(requests, returnResponses: true);

Retrieving Metadata

Use RetrieveTableMetadataAsync and RetrieveViewMetadataAsync to retrieve table and view metadata. For cached access, prefer ITableMetadataCache and IViewMetadataCache instead.

var tableMetadata = await _powerPortalsProService.RetrieveTableMetadataAsync("contact");
var viewMetadata = await _powerPortalsProService.RetrieveViewMetadataAsync(viewId);

Working with Files

Use GetFileInfoAsync to retrieve file or image metadata and optionally the binary content from a file or image column.

// Get file metadata only
var fileInfo = await _powerPortalsProService.GetFileInfoAsync("contact", contactId, "ppp_contract");

// Get file metadata and binary content
var fileWithData = await _powerPortalsProService.GetFileInfoAsync("contact", contactId, "ppp_contract", includeData: true);
var bytes = fileWithData.FileData;

IPowerPortalsProService Interface

Methods

Name
Parameters
Type
Description
AssociateAsyncTableRecordReference record
string relationshipName
IEnumerable<TableRecordReference> relatedRecords
EntityRole? role
Task<AssociateResponse>
Associates a record with one or more related records via a many-to-many relationship.
ClearAllCachesAsyncTask<IReadOnlyList<CacheClearResult>>
Clears every server-side Services.IClearableCache (table / view / privilege metadata, per-user privileges, environment-file settings) and rebuilds the localized-strings cache atomically — readers continue to see the previously loaded data until the new state is fully populated. Lazy caches refill on the next request that needs them. The HTTP endpoint behind this call is gated by [Authorize(Roles = 'SystemAdmin')]. Server-side direct callers should gate appropriately at their own boundary.
ClearCacheAsyncstring name
Task<CacheClearResult>
Clears one named cache. Returns null when no registered cache matches name (case-insensitive); failures are wrapped in the result rather than thrown. Same auth gate as IPowerPortalsProService.ClearAllCachesAsync.
CreateFileArchiveAsyncCreateFileArchiveRequest request
Task<FileArchiveResult>
Builds an archive (currently zip; future formats live behind the CreateFileArchiveRequest.Format enum) containing every record's file payload for the named table / column pair. Uses the same per-record permission chain as String,System.Boolean) — unauthorized / missing rows are silently dropped from the archive. Duplicate filenames are disambiguated by suffixing ' (2)', ' (3)', … so the archive never overwrites entries.
CreateRecordAsyncTableRecord record
Task<CreateResponse>
Creates a new record in Dataverse.
DeleteRecordAsyncstring tableLogicalName
Guid id
Task<DeleteResponse>
Deletes a record from Dataverse by table name and record ID.
DisassociateAsyncTableRecordReference record
string relationshipName
IEnumerable<TableRecordReference> relatedRecords
EntityRole? role
Task<DisassociateResponse>
Removes an association between a record and one or more related records via a many-to-many relationship.
ExecuteAsyncOrganizationRequest request
Task<OrganizationResponse>
Executes a single organization request against Dataverse.
ExecuteMultipleAsyncIEnumerable<OrganizationRequest> requests
bool returnResponses
Task<List<OrganizationResponse>>
Executes multiple organization requests in a single database transaction. If any request fails, all changes in the batch are rolled back.
GetCacheNamesAsyncTask<IReadOnlyList<string>>
Returns the names of every server-side Services.IClearableCache, suitable for an admin UI that wants to render per-cache clear buttons. Same auth gate as IPowerPortalsProService.ClearAllCachesAsync applies on the HTTP endpoint.
GetEnvironmentFileSettingsAsyncTask<EnvironmentFileSettings>
Retrieves the environment-wide file upload settings (blocked extensions list and maximum upload size) from the Dataverse organization record. Intended for clients that want to mirror server-side enforcement — rejecting files with a blocked extension or above the size ceiling before the upload round-trips to Dataverse.
GetFileInfoAsyncstring tableName
Guid recordId
string columnName
bool includeData
Task<FileInfo>
Retrieves file information and optionally the binary content from a file or image column in Dataverse.
GetFileInfosAsyncstring tableName
IEnumerable<Guid> recordIds
string columnName
bool includeData
Task<IEnumerable<FileInfo>>
Batched retrieval of file information for many records of the same table / column in a single round trip. Internally fans the per-record fetches out in parallel and returns the combined list. The same per-record permission-handler chain runs as for the single-record call; failed lookups are dropped from the response rather than failing the whole batch. Used by FileGrid's 'Download All' / 'Download Selected' so the client can build a zip without firing N HTTP requests.
RetrieveRecordAsyncstring tableLogicalName
Guid id
IEnumerable<string> columns
Task<TableRecord>
Retrieves a single record from Dataverse by table name and record ID.
RetrieveRecordsAsyncstring fetchXml
Task<RetrieveRecordsResponse>
Retrieves multiple records from Dataverse using a FetchXML query. Supports filtering, sorting, paging, linked entities, and aggregate queries.
RetrieveTableMetadataAsyncstring tableLogicalName
Task<TableMetadata>
Retrieves table metadata from Dataverse, including column definitions, relationships, and display configuration.
RetrieveViewMetadataAsyncGuid viewId
Task<ViewMetadata>
Retrieves view metadata from Dataverse, including the view's FetchXML query, columns, and display configuration.
RetrieveViewsForTableAsyncstring tableLogicalName
Task<IEnumerable<ViewMetadata>>
Retrieves every view metadata record for a table. Used by grids that need to enumerate the available views (view-picker, default-view resolution, etc.). The server-side implementation reads from the in-process IViewMetadataCache; the WASM client hits an HTTP endpoint that does the same on the server.
UpdateRecordAsyncTableRecord record
Task<UpdateResponse>
Updates an existing record in Dataverse. Only the properties set on the record are sent to Dataverse.
Name: AssociateAsync
Parameters: TableRecordReference record
string relationshipName
IEnumerable<TableRecordReference> relatedRecords
EntityRole? role
Type: Task<AssociateResponse>
Description: Associates a record with one or more related records via a many-to-many relationship.
Name: ClearAllCachesAsync
Type: Task<IReadOnlyList<CacheClearResult>>
Description: Clears every server-side Services.IClearableCache (table / view / privilege metadata, per-user privileges, environment-file settings) and rebuilds the localized-strings cache atomically — readers continue to see the previously loaded data until the new state is fully populated. Lazy caches refill on the next request that needs them. The HTTP endpoint behind this call is gated by [Authorize(Roles = 'SystemAdmin')]. Server-side direct callers should gate appropriately at their own boundary.
Name: ClearCacheAsync
Parameters: string name
Type: Task<CacheClearResult>
Description: Clears one named cache. Returns null when no registered cache matches name (case-insensitive); failures are wrapped in the result rather than thrown. Same auth gate as IPowerPortalsProService.ClearAllCachesAsync.
Name: CreateFileArchiveAsync
Parameters: CreateFileArchiveRequest request
Type: Task<FileArchiveResult>
Description: Builds an archive (currently zip; future formats live behind the CreateFileArchiveRequest.Format enum) containing every record's file payload for the named table / column pair. Uses the same per-record permission chain as String,System.Boolean) — unauthorized / missing rows are silently dropped from the archive. Duplicate filenames are disambiguated by suffixing ' (2)', ' (3)', … so the archive never overwrites entries.
Name: CreateRecordAsync
Parameters: TableRecord record
Type: Task<CreateResponse>
Description: Creates a new record in Dataverse.
Name: DeleteRecordAsync
Parameters: string tableLogicalName
Guid id
Type: Task<DeleteResponse>
Description: Deletes a record from Dataverse by table name and record ID.
Name: DisassociateAsync
Parameters: TableRecordReference record
string relationshipName
IEnumerable<TableRecordReference> relatedRecords
EntityRole? role
Type: Task<DisassociateResponse>
Description: Removes an association between a record and one or more related records via a many-to-many relationship.
Name: ExecuteAsync
Parameters: OrganizationRequest request
Type: Task<OrganizationResponse>
Description: Executes a single organization request against Dataverse.
Name: ExecuteMultipleAsync
Parameters: IEnumerable<OrganizationRequest> requests
bool returnResponses
Type: Task<List<OrganizationResponse>>
Description: Executes multiple organization requests in a single database transaction. If any request fails, all changes in the batch are rolled back.
Name: GetCacheNamesAsync
Type: Task<IReadOnlyList<string>>
Description: Returns the names of every server-side Services.IClearableCache, suitable for an admin UI that wants to render per-cache clear buttons. Same auth gate as IPowerPortalsProService.ClearAllCachesAsync applies on the HTTP endpoint.
Name: GetEnvironmentFileSettingsAsync
Type: Task<EnvironmentFileSettings>
Description: Retrieves the environment-wide file upload settings (blocked extensions list and maximum upload size) from the Dataverse organization record. Intended for clients that want to mirror server-side enforcement — rejecting files with a blocked extension or above the size ceiling before the upload round-trips to Dataverse.
Name: GetFileInfoAsync
Parameters: string tableName
Guid recordId
string columnName
bool includeData
Type: Task<FileInfo>
Description: Retrieves file information and optionally the binary content from a file or image column in Dataverse.
Name: GetFileInfosAsync
Parameters: string tableName
IEnumerable<Guid> recordIds
string columnName
bool includeData
Type: Task<IEnumerable<FileInfo>>
Description: Batched retrieval of file information for many records of the same table / column in a single round trip. Internally fans the per-record fetches out in parallel and returns the combined list. The same per-record permission-handler chain runs as for the single-record call; failed lookups are dropped from the response rather than failing the whole batch. Used by FileGrid's 'Download All' / 'Download Selected' so the client can build a zip without firing N HTTP requests.
Name: RetrieveRecordAsync
Parameters: string tableLogicalName
Guid id
IEnumerable<string> columns
Type: Task<TableRecord>
Description: Retrieves a single record from Dataverse by table name and record ID.
Name: RetrieveRecordsAsync
Parameters: string fetchXml
Type: Task<RetrieveRecordsResponse>
Description: Retrieves multiple records from Dataverse using a FetchXML query. Supports filtering, sorting, paging, linked entities, and aggregate queries.
Name: RetrieveTableMetadataAsync
Parameters: string tableLogicalName
Type: Task<TableMetadata>
Description: Retrieves table metadata from Dataverse, including column definitions, relationships, and display configuration.
Name: RetrieveViewMetadataAsync
Parameters: Guid viewId
Type: Task<ViewMetadata>
Description: Retrieves view metadata from Dataverse, including the view's FetchXML query, columns, and display configuration.
Name: RetrieveViewsForTableAsync
Parameters: string tableLogicalName
Type: Task<IEnumerable<ViewMetadata>>
Description: Retrieves every view metadata record for a table. Used by grids that need to enumerate the available views (view-picker, default-view resolution, etc.). The server-side implementation reads from the in-process IViewMetadataCache; the WASM client hits an HTTP endpoint that does the same on the server.
Name: UpdateRecordAsync
Parameters: TableRecord record
Type: Task<UpdateResponse>
Description: Updates an existing record in Dataverse. Only the properties set on the record are sent to Dataverse.