Telerik Data Access provides support for ASP.NET Web API services. Thus, you can easily leverage the power of Telerik Data Access in your N-Tier applications by exposing your model through HTTP-based Web API services. Telerik Data Access provides the Service Wizard that allows you to expose Telerik Data Access Domain Model via Web API. This topic will show you how to achieve this task.
Suppose, you have an ASP.NET Web Application project and you have created a new Telerik Data Access Domain Model.
ASP.NET Web API allows you to serialize your domain classes to JSON, XML, or some other format, and then write the serialized data into the body of the HTTP response message. As long as a client can read the serialization format, it can deserialize the object. Most clients can parse either XML or JSON. Furthermore, the client can specify which format it wants by setting the Accept header in the HTTP request message.
To create controllers for your domain classes:
Right-click the RLINQ file in Solution Explorer and select Add Telerik Data Access Service.....
If you don't have a RLINQ file, e.g. you have a Fluent Model project, you can start the wizard by using the context menu of the Web Application where the service will reside.
This will bring up the Service Wizard. The first page of the wizard is the Select Source and Output dialog. From the Select context drop-down select your domain context. By default, it is named EntitiesModel. From the Host in Project drop-down select the project that will contain the output. In this example, the project that contains the domain model and the project that will contain the generated controllers are the same - WebApplication. Check the Use Existing Project option and select your web project.
Click Next to continue. The Select Service Type dialog appears. You need to select the service type. Select ASP.NET Web API Service.
Click Next. In the Service Configuration dialog, select which entities to be generated as part of the service. By default all entities are selected. Also you have the option to specify what CUD operations can be performed on the generated entities. More special is the case when your domain model contains views. You can use the views only for read operations. By default, if your view doesn't have a primary key, the corresponding entry in the Add Telerik Data Access Service wizard is disabled. If you want to expose a view through a service, you need to specify a primary key in the Visual Designer.
Once all selections are done, click Next to proceed. In the Preview dialog, review all changes that will be done in your project.
Click Finish to generate the Api Controllers. Web API is currently delivered as part of ASP.NET MVC4, but you can also install it through a Nuget package. When you click Finish and the wizard will ask you to confirm the download of the Nuget package.
To see what is the outcome of the service generation, check out the Service Generation Outcome topic.