Over the years, this blog has been about many different things related to software development with Microsoft technologies. Since my current role focuses on PowerApps & Flow, that's what it's primarily about right now.
“I want to use Erwin [or Visio or Visual Studio or…] to graphically design the CRM entity model, then have the actual CRM entities generated off of the tool I used to design the entities.”
While I am not aware of a direct way to do this with any ERD tools, there is a multi-step process you can use as long as your ERD designer can generate a SQL or Access database:
Use your ERD designer to model your entities, fields and relationships
Generate a SQL or Access database from the designer
Of course, you’ll need to make sure you don’t pick data types in your diagram that the xrmspeedy tool can’t translate to CRM types, but this approach can be used as a productivity enhancement to those who prefer to diagram out their entities and generated them. Since this is an open source tool, you might consider contributing feedback if you have ideas for improvement. After a little trial and error, I’ve found I get value out of using Visual Studio’s Entity Framework Designer plus this tool when brainstorming data models and building POCs. Your Mileage May Vary (YMMV).
“I love early bound code because of compile time checking, LINQ query enablement, etc. I want to batch update a bunch of records, but OrganizationServiceContext.SaveChanges() executes under the hood as one web service call per entity. How do I batch update? Also, how do I make sure that only the fields I change are updated?”
The answer is that you basically have to combine your crmsvcutil.exe generated code with ExecuteMultipleResults. Here’s an example:
var conn = CrmConnection.Parse("USE A VALID connection string using appropriate format documented at https://msdn.microsoft.com/en-us/library/jj602970.aspx");
var ctx = new marcsctest1Context(new OrganizationService(conn));
// NOTE: The query below uses LINQ projection. The CRM LINQ provider will translate this to a query that only returns ID & Name
var query =
from a in ctx.AccountSet
select new Account
{
Id = a.Id,
Name = a.Name
};
var executeMultipleRequest = new ExecuteMultipleRequest()
{
Settings = new ExecuteMultipleSettings(){
ContinueOnError = false,
ReturnResponses = true
},
Requests = new OrganizationRequestCollection()
};
foreach (var account in query)
{
account.Name += " - Updated";
//UpdateObject is required to set the EntityState to Changed because it is readonly through crmsvcutil generated entities
I’ve been a longtime fan of LINQPad (www.linqpad.net) as a general purpose tool for executing LINQ queries with various LINQ enabled technologies as well as a general purpose scratchpad for testing out .NET code without having to fire up Visual Studio. I’ve already blogged about how to use LINQPad to work with the CRM Online SOAP service:
One thing that may not be obvious is how to use LINQPad to query the OData service that comes with Dynamics CRM Online. Using the same basic concept that I showed with the SOAP service, I created a video walkthrough of how to interact with the OData service from LINQPad:
Here’s the LINQPad starter code I showed in the video:
var clientId = "[YOUR_CLIENT_ID]";
var resource = "https://[YOUR_INSTANCE].crm.dynamics.com";
var redirectUri = new Uri("http://linqpad"); //replace with your redirect uri
var authContext = new AuthenticationContext("https://login.windows.net/common/oauth2/authorize", false);
var authResult = authContext.AcquireToken(resource, clientId, redirectUri, PromptBehavior.Auto);
Util.ClearResults();
var ctx = new marcsctest1Context(new Uri(resource + "/XRMServices/2011/OrganizationData.svc/"));
One of the things I did, after creating the video, was to write a reusable helper method in the LINQPad MyExtensions class so I can reuse the code to get the access token across multiple LINQPad query sessions. Here’s the code for the extension:
void Main()
{
// Write code to test your extensions here. Press F5 to compile and run.
}
publicstaticclass MyExtensions
{
// Write custom extension methods here. They will be available to all queries.
staticstring LINQPadAccessToken = null;
publicstaticstring GetAccessToken()
{
if (LINQPadAccessToken != null)
{
return LINQPadAccessToken;
}
var clientId = "[YOUR_CLIENT_ID]";
var resource = "https://[YOUR_INSTANCE].crm.dynamics.com";
var redirectUri = new Uri("http://linqpad"); //your redirect uri
var authContext = new AuthenticationContext("https://login.windows.net/common/oauth2/authorize", false);
var authResult = authContext.AcquireToken(resource, clientId, redirectUri, PromptBehavior.Auto);
Util.ClearResults();
LINQPadAccessToken = authResult.AccessToken;
return LINQPadAccessToken;
}
}
Here’s a version of the code in my query tab that is simplified, after writing and leveraging the helper method:
var ctx = new marcsctest1Context(
new Uri("https://[YOUR_INSTANCE].crm.dynamics.com/XRMServices/2011/OrganizationData.svc/")
Note the call to MyExtensions.GetAccessToken() above. You could obviously refactor the GetAccessToken() method more to make it even more reusable, but I will leave that as an exercise for you.
This approach will become even more powerful once Dynamics CRM introduces the new OData v4 service endpoint:
As I mention in the video, once that happens, you’ll want to perform the codgen with the OData Client Code Generator instead of “Add Service Reference”:
CRM Online based solutions often run across the broader Microsoft Cloud, not just CRM Online alone. As they say, a picture is worth a thousand words. So here’s a picture that hits home this point at a high level.
To help people get started trying this environment out, I’ve created a video that walks you through setting up a trial for CRM Online, Office 365, and Microsoft Azure where all the services are provisioned for Single Sign On (SSO) under a single Azure Active Directory tenant and provide shared administration.
Debugging plugins in CRM Online just got a lot better with the latest version of the plugin registration tool that ships with CRM 2015. In the video below, I walk you through how to debug CRM Online plugins using Visual Studio.