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.

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 Class

Methods

Name
Parameters
Type
Description
AssociateAsyncTableRecordReference record
string relationshipName
IEnumerable<TableRecordReference> relatedRecords
Task<AssociateResponse>
Associates a record with one or more related records via a many-to-many relationship.
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
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.
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.
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.
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
Type: Task<AssociateResponse>
Description: Associates a record with one or more related records via a many-to-many relationship.
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
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: 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: 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: 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.