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
- Compile and copy
C1NorthwindIntegration.dll
to your C1 CMS's/Bin
folder. - Copy the connection string from the generated
App.config
in your project toWeb.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="Data Source=.\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" /> </connectionStrings> </configuration>
- Edit
/App_Data/Composite/Composite.config
and locate the following element:/configuration/Composite.Data.Plugins.DataProviderConfiguration/DataProviderPlugins
- 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
- Copy the sample project's
/TreeDefinitions/Northwind.xml
to your website's/App_Data/Composite/TreeDefinitions
folder. - Log in to the Administrative console.
- Switch to the Data perspective.
- 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=> ...); }