Customizing Ado.Net DataService Operations

Damir Dobric Posts

Next talks:



Follow me on Twitter: #ddobric




When working with ADO.NET Data Service based on Entity Framework provide you can really build up from the scratch in just few minutes service based access to any kind of relational data.
This can be very useful in many different application, but…
If you build serious software you will for sure need to do something in your data service, which is not provided out of the box. Unfortunately, because you did nothing to build up the service, there are not to many options to do something This might be painful.


For example, imagine you want to provide custom service operation GetCityNames which returns your custom type: MyEntity

[WebGet]public IQueryable<MyEntity> GetMyEntities()

When you try to start the service (open service URI in explorer) following error appears:

Method 'System.Linq.IQueryable`1[SampleDataService.MyEntity] GetMyEntities(System.String, System.String)' has a return type 'System.Linq.IQueryable`1[SampleDataService.MyEntity]' which is not supported for service operations.  Only IQueryable and IEnumerable generics of primitive types or entity types are supported as return types.

This means, you cannot use any complex custom type in the service.


The good news is that there is a method “RegisterKnownType”  which allows you to register your custom type:


The bad news is that it doesn’t work with Entity Framework provider. :(


Ok, but you think you could create the operation which use some EF-Type:

[WebGet] public IQueryable<City> GetBigCities(List<int> someInput);

This one fails with following error:

Method 'System.Linq.IQueryable`1[SampleDataService.City] GetBigCities(System.Collections.Generic.List`1[System.Int32])' has a parameter 'System.Collections.Generic.List`1[System.Int32] stations' of type 'System.Collections.Generic.List`1[System.Int32]' which is not supported for service operations. Only primitive types are supported as parameters.

The problem is that input parameter can be only of primitive types. List<int> is not such one. :(

But, there is one thing you can do:

[WebGet] public IQueryable<City> GetBigCities(int someInput);

This will work

Posted Sep 25 2009, 11:36 PM by Damir Dobric
Filed under: is a .Net Community Blog powered by daenet GmbH.