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
IPowerPortalsProServicedirectly. TheRecordContext,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 |
|---|---|---|---|
AssociateAsync | TableRecordReference record string relationshipName IEnumerable<TableRecordReference> relatedRecords | Task<AssociateResponse> | Associates a record with one or more related records via a many-to-many relationship. |
CreateRecordAsync | TableRecord record | Task<CreateResponse> | Creates a new record in Dataverse. |
DeleteRecordAsync | string tableLogicalName Guid id | Task<DeleteResponse> | Deletes a record from Dataverse by table name and record ID. |
DisassociateAsync | TableRecordReference 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. |
ExecuteAsync | OrganizationRequest request | Task<OrganizationResponse> | Executes a single organization request against Dataverse. |
ExecuteMultipleAsync | IEnumerable<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. |
GetFileInfoAsync | string 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. |
RetrieveRecordAsync | string tableLogicalName Guid id IEnumerable<string> columns | Task<TableRecord> | Retrieves a single record from Dataverse by table name and record ID. |
RetrieveRecordsAsync | string fetchXml | Task<RetrieveRecordsResponse> | Retrieves multiple records from Dataverse using a FetchXML query. Supports filtering, sorting, paging, linked entities, and aggregate queries. |
RetrieveTableMetadataAsync | string tableLogicalName | Task<TableMetadata> | Retrieves table metadata from Dataverse, including column definitions, relationships, and display configuration. |
RetrieveViewMetadataAsync | Guid viewId | Task<ViewMetadata> | Retrieves view metadata from Dataverse, including the view's FetchXML query, columns, and display configuration. |
UpdateRecordAsync | TableRecord record | Task<UpdateResponse> | Updates an existing record in Dataverse. Only the properties set on the record are sent to Dataverse. |
AssociateAsyncstring relationshipName
IEnumerable<TableRecordReference> relatedRecords
CreateRecordAsyncDeleteRecordAsyncGuid id
DisassociateAsyncstring relationshipName
IEnumerable<TableRecordReference> relatedRecords
ExecuteAsyncExecuteMultipleAsyncbool returnResponses
If any request fails, all changes in the batch are rolled back.
GetFileInfoAsyncGuid recordId
string columnName
bool includeData
RetrieveRecordAsyncGuid id
IEnumerable<string> columns
RetrieveRecordsAsyncSupports filtering, sorting, paging, linked entities, and aggregate queries.
RetrieveTableMetadataAsyncRetrieveViewMetadataAsyncUpdateRecordAsync