Tuesday, July 17, 2012

Project - PluginQuickDeploy Update 0.9.0.2

I have created a new version of pqd with minor changes.
Most important part is the NuGet Package.

Project Page: 
http://pqd.codeplex.com/ 

NuGet Package: 
https://nuget.org/packages/PluginQuickDeploy

NuGet Command: 
PM> Install-Package PluginQuickDeploy

Cheers, Markus

Wednesday, July 11, 2012

CRM 2011 - Accessing and filtering custom/crm WCF Data Service (oData) from sandboxed Plugin

As described in some MSDN-Forums and by Eric Pool, Quering data against the context directly via Linq in sandboxed plugins is not possible. You can retrieve the whole DataSet, but filtering is not possible.

If you need to access and filtering your results from an oData endpoint (also custom ones), you can use the following syntax.

Example OrganizationDataService (with FirstOrDefault):
//Define the Request URI
Guid accountId = new Guid("66BD3ABE-D2CA-E111-9E1F-000C29BDAB09");
string serviceAddress = @"http://crm:5555/DEV/XRMServices/2011/OrganizationData.svc/";
string accountQueryByPrimaryKey = string.Format("AccountSet(guid'{0}')", accountId.ToString());
Uri svcUri = new Uri(serviceAddress);
Uri accountUri = new Uri(string.Format("{0}{1}", serviceAddress, accountQueryByPrimaryKey));
 
//Create context and credentials ('My' is the name of the CRM organization, these classes are created when you add a service reference to CRM DataService endpoint)
CrmService.MyContext context = new CrmService.MyContext(svcUri);
context.Credentials = new System.Net.NetworkCredential("username", "password", "domain");
 
//Retrieve data
Account retrievedAccount = context.Execute<Account>(accountUri).FirstOrDefault();


Example Custom Service (with Enumeration):
// Define the Request URI
Uri svcUri = new Uri(@"http://crm:8888/MyDataService/CustomDataService.svc/");
Uri uriAccounts = new Uri(string.Format("{0}{1}", svcUri, "ACCOUNT(3)"));
 
// Create the context
DataServiceContext context = new DataServiceContext(svcUri)

// Enumerate over the query result.
StringBuilder sb = new StringBuilder();
foreach (ACCOUNT account in context.Execute<ACCOUNT>(uriAccounts)) { sb.AppendLine("Name: " + account.name); }

The trick is to use the oData (URI) for Filtering and to interprete just the results.

You can find the MSDN description here.

Friday, July 6, 2012

Project - PluginQuickDeploy

Today i have created my first project on Codeplex. Very nice page, the creation process was really easy and straight forward.

This small project was on my backlog for a very long time.

"PluginQuickDeploy" reduces the development time of Microsoft CRM Plugins, because the deployment to the test system is done by one click or directly in the build process (build events).

You can find the project here.

Saturday, March 10, 2012

Updating Database in EntityFramework "Code-First"

Today i have used EntityFramework "CodeFirst" for the first time.
I think it is a very interesting approach but the VisualStudio Integration could be more intuitive.

I have integrated it in an ASP.NET MVC Application. This task is described perfectly in a short video from Scott Hanselman.

What is missing in the video and took me some time, is the update of the database structure if the model has been changed (Well it is a MVC-Video, not an EF-Video). If you are using "Database First", you can simply update your .edmx file. In the "Code First" scenario we have to do some manual stuff. 

After you have created the application in the video (or your own EF-Based Application), run it and create some entries in the database. Than add an additional Property to one of your Model-Classes. For udpating the database structure run the following in the Package Manager Console.

PM> Enable-Migrations
PM> Add-Migration AddAppointmentSubject
PM> Update-Database

The "AddAppointmentSubject" can be named by your own. Here the structure is <task><class><property>.

There seems to be some issues/changes with the Version 5 (PreRelease) of EntityFramework. This stuff is running great on 4.3.1.

More details about updating the Model (e.g. new classes) you can find here.

Kind Regards,
Markus