use ContractNamespace with Remote Linq

Nov 13, 2015 at 11:33 AM
Is it possible to use ContractNamespace with Remote Linq?

Usually I have separate client and server side contracts like
namespace MyApp.Client.ServiceContracts
    MyItemViewModel GetMyItemById(int id);
and on server side:
namespace MyApp.Host.ServiceContracts
    MyItem GetMyItemById(int id);
and I set the contract namespace in the server and client side app in the AssemblyInfo.cs like this:
[assembly: ContractNamespace("",
                              ClrNamespace = "MyApp.Host.ServiceContracts")]
And it does the mapping between my server and client side objects.

But if I do this with remote like this, it returns an empty array on client side.

So it looks like this on the client side:
IEnumerable<MyItemViewModel> GetMyItem(LambdaExpression serializableExpression);
And this is the server side:
IEnumerable<MyItem> GetMyItem(LambdaExpression serializableExpression);
Nov 15, 2015 at 8:38 PM
ContractNamespaceAttribute is specific to WCF/soap services and is not taken into account by remote linq.

However, remote linq provides extension points you can hook in to translate from one type to another:
  • A simple approach is to pass a custom lambda as queryable-provider to Expression.Execute() and apply a corresponding mapping in this lambda.
    (see /samples/RemoteQueryable/0_Standard/Server/QueryService.cs)
  • A more elegant way might be to use a custom type resolver on sever side
    (see /samples/RemoteQueryable/4_CustomTypeResolver/Server/CustomTypeResolver.cs)
Note that explicitly mapping types is only required for the query expression in order linq (linq-to-object, linq-to-entity, etc.) can apply the query to the data source. Mapping results to the client’s data types is done automatically.