unchase / Unchase.Odata.Connectedservice

:scroll: A Visual Studio extension for connecting to OData services with generating client-side C# proxy-classes
Apache License 2.0
44 stars 13 forks source link

QUESTION: Is the generated client proxy code compatible with net core 3.1? #37

Closed flevy73 closed 4 years ago

flevy73 commented 4 years ago

Hi,

We recently moved to net core 3.1 which meant that we had to switch to vs 2019 in order to have some kind of OData client proxy generation cababilities and tried out Unchase. Code generation works fine but when running our existing code it fails and it complains:

... return _context.Order .Expand(x => x.Order_Line) .Where(a => a.Submit_Date >= fromQueryDate.Value) .Where(a => a.Submit_Date.Value <= toQueryDate.Value) .OrderByDescending(x => x.Submit_Date.Value).Skip(page.PageNumber * page.PageSize).Take(page.PageSize).ToList();

  One or more errors occurred. (This target framework does not enable you to directly enumerate over a data service query. This is because enumeration automatically sends a synchronous request to the data service. Because this framework only supports asynchronous operations, you must instead call the BeginExecute and EndExecute methods to obtain a query result that supports enumeration.)

System.AggregateException: One or more errors occurred. (This target framework does not enable you to directly enumerate over a data service query. This is because enumeration automatically sends a synchronous request to the data service. Because this framework only supports asynchronous operations, you must instead call the BeginExecute and EndExecute methods to obtain a query result that supports enumeration.) ---> System.NotSupportedException: This target framework does not enable you to directly enumerate over a data service query. This is because enumeration automatically sends a synchronous request to the data service. Because this framework only supports asynchronous operations, you must instead call the BeginExecute and EndExecute methods to obtain a query result that supports enumeration.

Changing the code a litte bit to: var query = _context.Order .Expand(x => x.Order_Line) .Where(a => a.Submit_Date >= fromQueryDate.Value) .Where(a => a.Submit_Date.Value <= toQueryDate.Value) .OrderByDescending(x => x.Submit_Date.Value).Skip(page.PageNumber * page.PageSize).Take(page.PageSize);

        var result = await query.ToAsync();

        return result.ToList();

where the ToAsync method is:

public static class QueryExtensions { public async static Task<IEnumerable> ToAsync(this IQueryable query) { if (query is System.Data.Services.Client.DataServiceQuery dataServiceQuery) { var factory = new TaskFactory<IEnumerable>(); var result = await factory.FromAsync( dataServiceQuery.BeginExecute(null, null), a => dataServiceQuery.EndExecute(a));

            return result;
        }

        return query;
    }
}

causes a new error: One or more errors occurred. (An error occurred while processing this request.) System.AggregateException: One or more errors occurred. (An error occurred while processing this request.) ---> System.Data.Services.Client.DataServiceQueryException: An error occurred while processing this request. ---> System.Data.Services.Client.DataServiceClientException: NotFound at System.Data.Services.Client.BaseAsyncResult.EndExecute[T](Object source, String method, IAsyncResult asyncResult) at System.Data.Services.Client.QueryResult.EndExecuteQuery[TElement](Object source, String method, IAsyncResult asyncResult) --- End of inner exception stack trace --- at System.Data.Services.Client.QueryResult.EndExecuteQuery[TElement](Object source, String method, IAsyncResult asyncResult) at System.Data.Services.Client.DataServiceRequest.EndExecute[TElement](Object source, DataServiceContext context, String method, IAsyncResult asyncResult) at System.Data.Services.Client.DataServiceQuery`1.EndExecute(IAsyncResult asyncResult)

Which deep down seems to be caused by an underlying 404 (although the query seems correct when I copy it and run it in a browser).

So question is: Is there something wrong in my code or some kind of incompatibility issue?

unchase commented 4 years ago

See the topic on StackOverflow or this issue.