When using a WCF 5.6 data service, howto: get typedviews

Posts   
 
    
Posts: 24
Joined: 19-Feb-2007
# Posted on: 08-Apr-2014 18:43:46   

Hello, I am able to return Entity objects for use in my HTML5 Grid (commented out below MyEntityTableName) trying to get a TypedView (MyViewName) to return. This errors the service.

Regards.


public class MyServiceName : LLBLGenProODataServiceBase<LinqMetaData>
    {
        // This method is called only once to initialize service-wide policies.
        public static void InitializeService(DataServiceConfiguration config)
        {
            // TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
            // Examples:
            // config.SetEntitySetAccessRule("MyEntityTableName", EntitySetRights.All);
             config.SetEntitySetAccessRule("MyViewName", EntitySetRights.All);

            // config.SetServiceOperationAccessRule("MyServiceOperation", ServiceOperationRights.All);
            config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
        }

        protected override LinqMetaData CreateLinqMetaDataInstance()
        {
            // adapter
           // return new LinqMetaData(new DataAccessAdapter());
            // selfservicing:
             return new LinqMetaData();
        }

        protected override ITransactionController CreateTransactionControllerInstance()
        {
            // adapter
           // return new DataAccessAdapter();
            // selfservicing:
            return new Transaction(System.Data.IsolationLevel.ReadCommitted, "Trans");
        }

        protected override IUnitOfWorkCore CreateUnitOfWorkInstance()
        {
            // adapter
            return new UnitOfWork2();
            // selfservicing
            // return new UnitOfWork();
        }

        protected override string ContainerName
        {
            get { return "MyServiceName"; }
        }

    }

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 08-Apr-2014 23:34:45   

Not sure I understand the problem, nor the code snippet. Are you trying to use Linq2LLBLGen to retrieve a TypedView? Or are you just trying to return a TypedView from a WCF service?

Could you please post the error/exception you get?

Posts: 24
Joined: 19-Feb-2007
# Posted on: 09-Apr-2014 03:11:36   

Hi, I am trying to retrieve TypedViews from a WCF service as JSON.

The sample I have there is from LLBL and works with my Entities but I am lost as how to get Typedview data out of a service.

I've attempted a Service Operation for the typed view by returning an IQueryable<T> where T = my typedview row. That fails also as an unknown return type.

I'm using LLBL 4.1 Self Servicing with an ASP.net empty project and a WCF DataService OData 5.6

Thank you !

Posts: 24
Joined: 19-Feb-2007
# Posted on: 09-Apr-2014 03:21:01   

Error when putting a SQL DB View name in place of an Entity name from line in 1st post.

The server encountered an error processing the request. The exception message is 'Exception has been thrown by the target of an invocation.'. See server logs for more details. The exception stack trace is:

at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) at System.Data.Services.DataServiceConfiguration.InvokeStaticInitialization(Type type) at System.Data.Services.DataServiceConfiguration.Initialize(Type type) at System.Data.Services.DataService1.CreateConfiguration(Type dataServiceType, IDataServiceMetadataProvider provider, Boolean isInternallyCreatedProvider) at System.Data.Services.DataService1.CreateProvider() at System.Data.Services.DataService1.EnsureProviderAndConfigForRequest() at System.Data.Services.DataService1.HandleRequest() at System.Data.Services.DataService`1.ProcessRequestForMessage(Stream messageBody) at SyncInvokeProcessRequestForMessage(Object , Object[] , Object[] ) at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs) at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 09-Apr-2014 10:12:10   

Typed views are not retrievable through linq, only entities. OData relies on Linq, so you can't return typed views through OData. You can return them through normal webmethods on a wepapi though, but not through OData. I think that's causing your problem.

For v4.2 we're currently looking into adding this, however it will require substantial changes to the linq provider so it might not be possible to do so.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 24
Joined: 19-Feb-2007
# Posted on: 09-Apr-2014 18:41:12   

Ah, that makes me feel better on why it was so hard to figure out. Thanks for the explanation that clarifies my new direction which is a custom OData provider that does not rely on entity domain type stuff.

Your code example works perfect with the entities, paging through a grid (Telerik RadGrid) resulted in a response size of 800bytes requests (in Fiddler) using client side binding, vs 18k byte requests when using PostBacks and server side binding, so being able to use typedviews this way would be huge.

Much Thanks from Phoenix AZ.