Classes and interfaces

In this section, each class and interface of the concept will be explained in details.

Kipon.Xrm.VirtualEntityPlugin

Extend Kipon.Xrm.VirtualEntityPlugin to create the datasource plugin for a virtual plugin.

Virtual entities is a powerfull feature of the Dynamics 365 CE platform that enable you to expose data from external datasources as entities in CRM. If none of the standard providers, such as OData v4 or Azure Cosmos DB applies to your datasource, you must implement the provider your self. This require you to write a plugin that basically impl. a method to get a single row by it key, and a method to query the data from a Dynamics 365 CE query.


using System;
namespace Kipon.PluginExample.Plugins.Virtual
{
    public class VirtualEntityPlugin : Kipon.Xrm.VirtualEntityPlugin
    {
        public Microsoft.Xrm.Sdk.Entity OnRetrieve(Guid primaryentityid, string primaryentityname)
        {
            return new Microsoft.Xrm.Sdk.Entity { LogicalName = primaryentityname, Id = primaryentityid };
        }

        public Microsoft.Xrm.Sdk.EntityCollection OnRetrieveMultiple(string primaryentityname, Microsoft.Xrm.Sdk.Query.QueryExpression query)
        {
            var result = new Microsoft.Xrm.Sdk.EntityCollection();
            for (var i = 0; i < 10; i++)
            {
                result.Entities.Add(new Microsoft.Xrm.Sdk.Entity { LogicalName = primaryentityname, Id = Guid.NewGuid() });
            }
            return result;
        }
    }
}

Above example shows the signature of a virtual entity plugin. Be aware that the method names, and the parameter names must match this example. You do not need to ask for Guid primaryentityid, string primaryentityname on the OnRetrieve, but then again, how would you know what to return.

Same goes for string primaryentityname, Microsoft.Xrm.Sdk.Query.QueryExpression query on the OnRetrieveMultiple method, but if you do not inject the query and the name of the virtual entity, then how would you know what to query.

You can inject other services such as Dynamics 365 CE SDK standard services, or any service that you implement in your plugin. As such, the virtual entity plugin is not difference from a normal plugin

Virtual entities only support Get and Query. Virtual entities does not support Create, Update, Delete, and as such they are readonly for the Dynamics 365 CE platform. If you need to perform updates to your database you can impl. actions, however you cannot use the Form designer to create the UI, because virtual entiteis are always readonly.

© Kipon ApS 2020, 2021, 2022, 2023. All content on the page is the property of Kipon ApS. Any republish or copy of this content is a violation. The content of this site is NOT open source, and cannot be copied, republished or used in any context without explcit permission from the owner.