ADO.net Data services projection error

Posts   
 
    
jssenyange
User
Posts: 18
Joined: 18-Feb-2008
# Posted on: 26-Oct-2009 08:56:36   

I am using LLBLGEN v2.6 final with dlls released on 2009-10-13.

I expose a custom class BTCustomer not the real entity Customer.

I expose an entity object using the code below:-


public IQueryable<BTCustomer> BTCustomers
        {
            get
            {
                return new LinqMetaData().Customer.
                    Where(c => c.CompanyId==123).
                    Take(50).
                    Select(c => new BTCustomer
                        {
                            Id = c.Id,
                            /* adittional Fields */
                        });
            }
        }

When I try to use projection with the url

localhost/DataService.svc/BTCustomers?$select=Id

I get a null reference exception error

Object reference not set to an instance of an object. at SD.LLBLGen.Pro.LinqSupportClasses.LinqUtils.ObtainObjectValuesFromListOfObjects(IList listOfObjects, List`1 listOfFields)

at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleBinaryExpressionSeparateOperands(BinaryExpression expressionToHandle, Expression leftSide, Expression rightSide)

at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleBinaryExpressionBooleanOperator(BinaryExpression expressionToHandle)

at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleExpression(Expression expressionToHandle)

at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleExpression(Expression expressionToHandle)

at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleDbFunctionCallExpression(DbFunctionCallExpression expressionToHandle)

at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleExpression(Expression expressionToHandle)

at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleExpression(Expression expressionToHandle)

at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleProjectionExpression(ProjectionExpression expressionToHandle)

at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleExpression(Expression expressionToHandle)

at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleExpression(Expression expressionToHandle)

at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleSelectExpression(SelectExpression expressionToHandle, SelectExpression newInstance)

at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleSelectExpression(SelectExpression expressionToHandle)

at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleSelectExpression(SelectExpression expressionToHandle)

at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleExpression(Expression expressionToHandle)

at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleExpression(Expression expressionToHandle)

at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleSelectExpression(SelectExpression expressionToHandle, SelectExpression newInstance)

at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleSelectExpression(SelectExpression expressionToHandle)

at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleSelectExpression(SelectExpression expressionToHandle)

at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleSortClauseExpression(SortClauseExpression expressionToHandle)

at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleExpression(Expression expressionToHandle)

at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleExpression(Expression expressionToHandle)

at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleSelectExpression(SelectExpression expressionToHandle, SelectExpression newInstance)

at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleSelectExpression(SelectExpression expressionToHandle)

at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleSelectExpression(SelectExpression expressionToHandle)

at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.GenericExpressionHandler.HandleExpression(Expression expressionToHandle)

at SD.LLBLGen.Pro.LinqSupportClasses.ExpressionHandlers.QueryExpressionBuilder.HandleExpression(Expression expressionToHandle)

at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.HandleExpressionTree(Expression expression)

at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.Execute(Expression expression)

at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.System.Linq.IQueryProvider.Execute(Expression expression)

at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProQuery`1.Execute()

at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProQuery`1.System.Collections.IEnumerable.GetEnumerator()

at System.Data.Services.Internal.ProjectedWrapper.EnumerableWrapper.GetEnumerator()

at System.Data.Services.Internal.ProjectedWrapper.EnumerableWrapper.System.Collections.IEnumerable.GetEnumerator()

at System.Data.Services.WebUtil.GetRequestEnumerator(IEnumerable enumerable)

at System.Data.Services.DataService`1.SerializeResponseBody(RequestDescription description, IDataService dataService)

at System.Data.Services.DataService`1.HandleNonBatchRequest(RequestDescription description)

at System.Data.Services.DataService`1.HandleRequest()

The Linq Debug trace

Initial expression to process: value(SD.LLBLGen.Pro.LinqSupportClasses.DataSource`1[C4World.BusinessEntities.EntityClasses.CustomerEntity]).Where(c => c.CompanyId==123).Take(50).Select(c => new BTCustomer() {Id = c.Id}).Select(p => IIF((p = null), null, new ProjectedWrapper1() {ResourceTypeName = "DataService.BTCustomer", PropertyNameList = "Id", ProjectedProperty0 = Convert(Convert((p As BTCustomer).Id))})).OrderBy(p => Convert(p.ProjectedProperty0).Value).Take(50)

Any one got an Idea why projection does not work?

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 26-Oct-2009 13:40:03   

Please move the Take() to the end of the linq query.

I think the following should work.

        public IQueryable<BTCustomer> BTCustomers
        {
            get
            {
                var q = from c in metaData.Customer
                    Where(c.CompanyId==123)
                    Select(c => new BTCustomer
                        {
                            Id = c.Id,
                            /* adittional Fields */
                        }).Take(50);
                return q;
            }
        }
gittaylor
User
Posts: 6
Joined: 22-Sep-2009
# Posted on: 26-Oct-2009 14:21:45   

Walaa wrote:

Please move the Take() to the end of the linq query.

I think the following should work.

        public IQueryable<BTCustomer> BTCustomers
        {
            get
            {
                var q = from c in metaData.Customer
                    Where(c.CompanyId==123)
                    Select(c => new BTCustomer
                        {
                            Id = c.Id,
                            /* adittional Fields */
                        }).Take(50);
                return q;
            }
        }

Still the same exception. Even removing limiting the number of records to be returned still throws the same exception.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39862
Joined: 17-Aug-2003
# Posted on: 26-Oct-2009 14:41:44   

First, make sure the query runs properly in a normal .net method, so outside data services, just directly fetching the data.

If that works, please enable Linq Tracing at level 3 in the services' config file. This should give a text representation of the query. Please post that. (the exception occurs in the handling of the 'where', which should work properly.

Frans Bouma | Lead developer LLBLGen Pro
gittaylor
User
Posts: 6
Joined: 22-Sep-2009
# Posted on: 26-Oct-2009 16:02:22   

Otis wrote:

First, make sure the query runs properly in a normal .net method, so outside data services, just directly fetching the data.

If that works, please enable Linq Tracing at level 3 in the services' config file. This should give a text representation of the query. Please post that. (the exception occurs in the handling of the 'where', which should work properly.

The query works, also when accessing data via other operations except for projection.

Text representation of the query


value(SD.LLBLGen.Pro.LinqSupportClasses.DataSource`1[DataService.BusinessEntities.EntityClasses.CustomerEntity]).Where(c => (c.CompanyId = 123)).Select(c => new BTCustomer() {Id = c.Id, FullName = c.FullName, CompanyId = c.CompanyId}).Select(p => IIF((p = null), null, new ProjectedWrapper1() {ResourceTypeName = "DataServiceClasses.BTCustomer", PropertyNameList = "Id", ProjectedProperty0 = Convert(Convert((p As BTCustomer).Id))})).OrderBy(p => Convert(p.ProjectedProperty0).Value).Take(50)

gittaylor
User
Posts: 6
Joined: 22-Sep-2009
# Posted on: 26-Oct-2009 16:07:40   

Attached is an illustration project

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39862
Joined: 17-Aug-2003
# Posted on: 26-Oct-2009 17:28:11   

gittaylor wrote:

Attached is an illustration project

you didn't attach anything wink (likely you didn't click the upload button)

Frans Bouma | Lead developer LLBLGen Pro
gittaylor
User
Posts: 6
Joined: 22-Sep-2009
# Posted on: 27-Oct-2009 07:55:39   

Otis wrote:

gittaylor wrote:

Attached is an illustration project

you didn't attach anything wink (likely you didn't click the upload button)

Sorry, I have re-attached it to the post.

http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=16796&StartAtMessage=0&#93933

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39862
Joined: 17-Aug-2003
# Posted on: 27-Oct-2009 10:53:33   

will look into it.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39862
Joined: 17-Aug-2003
# Posted on: 27-Oct-2009 11:28:37   

I see you didn't use the ADO.NET dataservices templates? Please use these, combined with the templates you'd normally would use, as extra code has to be generated.

You can obtain these templates either from the customer area (2.6 section, at the bottom: 3rd party), or from the additional downloads section on the main site. Please use these templates and try again. The problem with the linq query is the wrapping applied to it:

value(SD.LLBLGen.Pro.LinqSupportClasses.DataSource`1[DataService.BusinessEntities.EntityClasses.CustomerEntity]).Where(c => (c.CompanyId = 123)).Select(c => new BTCustomer() {Id = c.Id, FullName = c.FullName, CompanyId = c.CompanyId}).Select(p => IIF((p = null), null, new ProjectedWrapper1() {ResourceTypeName = "DataServiceClasses.BTCustomer", PropertyNameList = "Id", ProjectedProperty0 = Convert(Convert((p As BTCustomer).Id))})).OrderBy(p => Convert(p.ProjectedProperty0).Value).Take(50)

This gives a problem as this is code which has to run in-memory, yet it is part of the query and thus is tried to be converted to a sql fragment which fails.

Please read the enclosed readme of the ado.net dataservices templates.

Frans Bouma | Lead developer LLBLGen Pro
jssenyange
User
Posts: 18
Joined: 18-Feb-2008
# Posted on: 28-Oct-2009 12:33:56   

Otis wrote:

I see you didn't use the ADO.NET dataservices templates? Please use these, combined with the templates you'd normally would use, as extra code has to be generated.

You can obtain these templates either from the customer area (2.6 section, at the bottom: 3rd party), or from the additional downloads section on the main site. Please use these templates and try again. The problem with the linq query is the wrapping applied to it:

Please read the enclosed readme of the ado.net dataservices templates.

I obtained the templates but now the new error is

The service does not expose IProjectionProvider interface which is required when top level results are paged. Request could not be processed.

This happens regardless of whether I have enabled or disabled paging in ado.net data services.

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 28-Oct-2009 16:04:50   

Is there a stack trace for this wierd exception?

jssenyange
User
Posts: 18
Joined: 18-Feb-2008
# Posted on: 29-Oct-2009 08:13:21   

Walaa wrote:

Is there a stack trace for this wierd exception?

I had to override HandleException method in the service to get the exception stack trace.

Message: The service does not expose IProjectionProvider interface which is required when projection is requested. Request could not be processed.

stack trace: at System.Data.Services.Providers.ReflectionServiceProvider.ApplyProjections(IQueryable source, ProjectionNode projection)

at System.Data.Services.RequestQueryProcessor.GenerateQueryResult()

at System.Data.Services.RequestQueryProcessor.ProcessQuery()

at System.Data.Services.RequestQueryProcessor.ProcessQuery(IDataService service, RequestDescription description)

at System.Data.Services.RequestUriProcessor.ProcessRequestUri(Uri absoluteRequestUri, IDataService service)

at System.Data.Services.DataService`1.ProcessIncomingRequestUri()

at System.Data.Services.DataService`1.HandleRequest()

Source: Microsoft.Data.Services

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39862
Joined: 17-Aug-2003
# Posted on: 29-Oct-2009 09:43:31   

We can't find a single reference to the interface IProjectionProvider, so we have no idea what it is or where it comes from. We also have never heard of this error before. If you're using vs.net 2010 beta2, please use astoria 1.0 from vs.net 2008 sp1.

So i.o.w. we don't know what this error means as it's thrown by .NET but there's no reference to what IProjectionProvider is...

Frans Bouma | Lead developer LLBLGen Pro
jssenyange
User
Posts: 18
Joined: 18-Feb-2008
# Posted on: 29-Oct-2009 09:59:38   

Otis wrote:

We can't find a single reference to the interface IProjectionProvider, so we have no idea what it is or where it comes from. We also have never heard of this error before. If you're using vs.net 2010 beta2, please use astoria 1.0 from vs.net 2008 sp1.

So i.o.w. we don't know what this error means as it's thrown by .NET but there's no reference to what IProjectionProvider is...

I was trying to upgrade our service to make use of the ADO.net data service 1.5 CTP v2 which has new features we wanted to make use of like paging and projection.

I guess I will wait.