In ADO.NET Data Service CTP V1.5 we can query the Entity records count before downloading the whole entity using $count .
1) Create ASP.NET Web Application.
2 ) Add ADO.NET Data Service Template .
3) Now we need to define/Create our Data source which we need Surface via ADO.NET Data Service . Here i am going to use Customer ,Order tables from North wind DB as my entity .
Now Add ADO.NET Entity Framework model template to the project and follow the Wizard .
Now we need to add manually the following two References from the directory where ADO.NET Data service CTP V 1.5 installed . [ Note: Remove old Version 1.0 Reference System.Data.Services, System.Data.Services.Client before adding new version]
The above step is very important, otherwise you wont able to use $count operator .
using System;
usingSystem.Collections.Generic;
usingSystem.Data.Services;
usingSystem.Linq;
usingSystem.ServiceModel.Web;
usingSystem.Web;
namespaceNewDataService
{
public classWebDataService1: DataService<NorthwindEntities>
{
public static voidInitializeService(IDataServiceConfiguration config)
{
config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
}
}
}
After paramterizing the DataService browse the .SVC
Now in Brower Address bar type the following rest URI.
http://localhost:51204/WebDataService1.svc/Orders/$count
The result of the above REST URL tells Orders Entity has 830 Records.
Nandri(Thanks)
R.Seenivasaragavan.
No comments:
Post a Comment