I’ve been interested in a while to try to see if I could take a model from Entity Framework and push it into CRM using the Metadata API. If your not familiar with ADO.NET Entity Framework, it was first released with .NET 3.5 SP1 and the second version of it is part of the upcoming VS2010/.NET 4 release. You can separate out EF into two key parts the Entity Data Mode (EDM) and the Entity Framework API that’s used to work with the data using the EDM. In working on my upcoming Silverlight book (http://www.slria.com) I’ve been looking at some different techniques for working with data across both traditional databases and CRM. That seemed like the perfect excuse to spend a few minutes (ok a little longer than that) building a tool that would consume the Entity Framework Model and push it into a CRM Entity Model using the metadata API.
So to get started, I defined an EDM using the Course database that I’m using as part of my examples for the book. The following is a snippet from the designer view of the EDM inside Visual Studio. Wouldn’t it be nice if the CRM team provided us some modeling tools like this!
Under the covers this stores in a .edmx file in your project which is really an XML file that contains the Conception Layer (What your application sees), the Storage layer (What it looks like in your database) and finally the Mapping layer which glues the two other layers together. You could simply work with the XML but the Entity Framework provides a nice metadata API that you can load this up and walk through it in memory.
Using the EF metadata API, I built a tool below to allow you to select entities from the model and push them to CRM. The tool is still industrial, and very much a prototype at this point but once you select the entities it allows you to push both the entity and the attributes into CRM
It handles some basic things like putting in spaces in the names etc. I still need to look more about descriptions and other useful things you might want to pull over but the basics end up in CRM. The following is a simple snapshot of CRM after running the tool.
I’m thinking this type of capability could be interesting for a number of things. In my example, I think it took about 10 minutes or so to do what would have taken me probably 5 hours to create all the duplicate definitions in CRM. It might also be interesting to go the other way from CRM into the EDM to allow visualization of the CRM model inside Visual Studio. I didn’t tackle that tonight, will save that for another day!