So yesterday, I was talking with Ted Pattison as he did a Critical Path class on the Great SharePoint Adventure (GSA) and a question was asked by one of his students about using Entity Framework to connect to a Oracle Database and then make an External Content Type and External List. I suggested that you can use various Database Technologies to connect to your backend Data and serve it up. in this case I am connecting to a SQL Azure Data in this case Northwind Customers and I will be using ADO.NET Entity Framework to work with it. I will then use WCF Data Service to render this data into OData format and use that URI as a source for my External Content Type in a Visual Studio SharePoint App.
In all of this I will be targeting a SharePoint Online Instance, but this can be used for On Prem, in fact the way i do my example I would either need to have (1) set up my SPO for Hybrid Inbound or it wouldn’t work because my URI is internally hosted, I could of course (2) do a Azure Cloud Service [as i have done in previous posts] as well.
Grab the Code here: http://code.msdn.microsoft.com/SQL-Azure-to-EF5-to-OData-2b2bd362
For this you will need a Visual Studio Solution with two projects. One will be for the ASP.NET project that will make the connection to the SQL Azure Data and host it, alternatively this could be a Web Role Project targeting a Cloud Service in Azure. The second project will be a SharePoint App Model Project that will create the External Content Type.
Create a ASP.NET Project
As you can see above we are creating a project of an ASP.NET Empty Web Application. So, we are also targeting a SQL Azure Database, i want to show that to you, see below
We will be targeting a Database called FabianNorthWind
Above what you see is us adding a ADO.NET Entity Model to the project to connect to the Azure SQL Instance.
Follow the wizard through and you should see what I see here
Finally you will have your EF in your project
Save your project here and next we will have to add a WCF Data Service, we do this so we can have a URI to connect to that will expose the SQL Azure Data, or Oracle Data etc.
Above is our URI endpoint and it is at NWindCustomer.svc
Once you do that you will get a template helper as you see below, some of it is stubbed out for you. You will need to enter the name of your ADO.NET Entity Model as well as configure the access for the Data you want
As this is Demoware, I am going to use an (*) for the configuration and tell it to do “ALL” but you can be more discrete.
Once you have done that you can preview the .SVC file in a browser and you should see what i have below
by typing in Customers in the URI, you will get an OData result set coming back to you. Pay attention to this URI you will need it for your next project.
Create a SharePoint App Project for your ECT
Ok, add a new project to your solution as i have below.
We are targeting a SPO tenant but this can be anywhere really. This is also a SharePoint Hosted App
Follow through on the wizard till your project is added.
Its really easy from here on in. You add a Content Type for an External Type to the new project
You provide the URI we have from the first project.
You select your Table, and leave the “check mark” for creating the List Instance so you will get your External Content Type and External List.
One you are done you will have an ECT and an EL as below in your project
If you open up your External Content Type you can see what I have below. At this point you can
- deploy it via visual studio
- give it to someone to upload to a farm
- deploy it manually yourself
here is the ECT below
Finally your project will look as i have below and you are done
I hope this is helpful, it was rather rushed, but i promised it in a few hours turnaround.
Why write this blog post?
Sure its late and YES I could be rotting my brain away on the Idiot Box, but what started off as a Taunt by Ram turned out to consume my life for 2 days straight but with useful results, challenges that were overcome, and a better appreciation for not just Cloud, but the integration of Cloud and On-Prem using Windows Azure. Let me tell you what I did, and how easy it was… in the end, plus the real implications of it.
First a little history – Pre Taunt
So, as I prepare for my sessions at #SPLive in Orlando in 3 weeks, I wanted to knock out a few Demos and make sure that I could showcase just about anything anyone asked of me based on the Session Abstract/Topic. In furtherance of that, I decided to do the following, build out solutions employing
SharePoint Designer 2013
- External Content Type using a Native SQL Data Connection
- External Content Type using an On-Prem (i.e. Hosted on one of my Dev Rig VMs) Windows Communications Foundation [WCF] Data Connection – JSON enabled
- External Content Type using a .NET Assembly (built on my Visual Studio 2012, Deployed as a Farm Solution to my On-Prem SP2013) Data Connection
- Workflow using the same On-Prem WCF above in my On-Prem Farm
Visual Studio 2012
- A Locally IIS hosted WCF Service Library that exposes Northwind data from a Local SQL Server 2012 Box
- A Locally IIS hosted OData Service Endpoint that exposes Northwind data from a Local SQL Server 2012 Box
- External Content Type built as a .NET Assembly to be deployed to my ON-Prem SharePoint 2013 Farm
- External Content Type AND External List SharePoint 2013 App built as an OData Sourced Application deployed to my ON-Prem SharePoint 2013 Farm
For every Instance of the WCF and the App Model External Content Type, I also targeted my Office 365 Tennant to surface the Data as well. I was pretty satisfied with myself until my good friend sent this tweet, and I know it was in jest…
but… I took it as a challenge and, I rarely back down from a challenge 🙂 so, since I have a MSDN subscription, there was “really” nothing holding me back besides my inexperience creating Azure Web Roles, which is what you need to do in order to have the requisite Data Access Points (URI) to create External Content Types and potentially Workflows.
What Next you say…
So, with a little research on Google scratch that, I mean Bing, I found a few MSDN, and TechNet blogs on how to create Web Roles, although not many of them “accurately” showed you how to use Visual Studio to DEPLOY your solution back to Azure. Anyway, it was surprisingly easy, although initially it was somewhat intimidating and i did get snagged on a GOTCHA which i will blog about later when doing a ASP.NET Web Role where it requires you to lower your version of the System.Data.Client assembly from 5.0 to 4.something in order for it work in Azure, i say that because it worked perfectly when I debugged it locally on my Visual Studio IIS. I also had to create an Azure SQL Instance and used a script I downloaded from CodePlex to restore a Northwind Database to my Azure SQL Instance and then I set up firewall rules to allow me to access it over the internet.
But with quick turn around and because i could just Refactor my original On-Prem code logic, I was able to create the following
Visual Studio 2012
- Azure ASP.NET Web Role that published as a Cloud Service which used OData via ADO.NET Entity Framework to get a Cloud based URI that i can do CRUD operations on
- Azure WCF Web Role that published as a Cloud Service which used WCF via ADO.NET Entity Framework to get a Cloud based URI that i can do CRUD operations on as well
Now I can really Mix and Match, I can
- Use Azure (Cloud) Hosted Data via an ON-Prem WCF or OData End Point and surface that information both on my ON-Prem SharePoint or my Office 365 Instance
- Use Azure (Cloud) Hosted Data via an Azure Cloud Service WCF or OData End Point and surface that information both on my ON-Prem SharePoint or my Office 365 Instance
- Plus everything I had when I started off
The takeaway here is that with very little investments in time and effort I extended my solution to a “MODERN” approach. I had Cloud in the sentence 🙂
Other Positive Implications
So, what made this so easy for me was I signed up for TFS Online here http://tfs.visualstudio.com/en-us/tfs-welcome.aspx and EVEN WITHOUT a MSDN Subscription you can sign up for FREE and get 5 accounts in one instance.
What I think is GOLD is…
- You have a place to store all your CODE/ Work and before you ask, it supports different formats (see image below)
- Your Code/Work is accessible from Anywhere you have an Internet Connection now
- You can reliably share your Code/Work with anyone now, rather than Zipping it up and Email it
- Need Help with some of you work… Invite people as smart or smarter than you to review our code, many hands make light load 🙂
- Most beneficial of all is that you can configure Continual Integration. I know my good friend Jeremy Thake always talk about Application Lifecycle Management (ALM) and you can employ some of those techniques from Azure through TFS Online and your Visual Studio with multiple Team Member… and guess what… FOR FREE
So that’s all I have to say, I guess we really Paid It Forward RAM, you encouraged me to do this, I in turn, documented my efforts and hope that someone else can take it from here.
Cheers all, have a great night. Oh yeah, VS 2013 is out now. GO get it.