Sample Code

Demonstrating how a read-only data provider exposes tables from a database using Entity Framework

The sample "EntityFrameworkNorthwindSample" project demonstrates how a read-only data provider exposes two tables (Suppliers and Products) to C1 CMS from the Microsoft's demo "Northwind" database using Entity Framework.

It includes 3 folders:

  • DataProvider
    Visual Studio project showing how Entity Framework can be used in a C1 CMS Data provider
  • SQL
    Script for creating a sample database (Northwind)
  • TreeDefinitions
    Sample tree for the CMS Console which shows data from the provider

Creating a demo database

If the Northwind database is not installed on your SQL server:

  • Run the script from the SQL folder

Registering the data provider in C1 CMS

  1. Compile and copy C1NorthwindIntegration.dll to your C1 CMS's /Bin folder.
  2. Copy the connection string from the generated App.config in your project to Web.config of your website, changing the connection string accordingly (server, database):
    <configuration>
    	<connectionStrings>
    		<add name="NorthwindEntities" connectionString="metadata=res://*/Northwind.csdl|res://*/Northwind.ssdl|res://*/Northwind.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=.\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />
    	</connectionStrings>
    </configuration>
  3. Edit /App_Data/Composite/Composite.config and locate the following element: /configuration/Composite.Data.Plugins.DataProviderConfiguration/DataProviderPlugins
  4. Add the following configuration element below (just before its end tag </DataProviderPlugins>):
    <add type="C1NorthwindIntegration.NorthwindDataProvider, C1NorthwindIntegration" name="NorthwindDataProvider" />

Showing data in the CMS Console

  1. Copy the sample project's /TreeDefinitions/Northwind.xml to your website's /App_Data/Composite/TreeDefinitions folder.
  2. Log in to the Administrative console.
  3. Switch to the Data perspective.
  4. Locate Northwind in the tree and expand it.

You will see products from the demo Northwind database grouped by their suppliers. The items are read-only.

Other uses

  • You can easily present data on the frontend by creating a Visual Function that uses Northwind Products and Suppliers.
  • You can also get your data using code like this:
using( var dc = new DataConnection())
{
   var product = dc.Get<IProduct>().Where( f=> ...);
}