AsEnumerable返回一个值,但没有返回值。
我似乎从odataQueryservice中提取某个值时遇到问题。
ODataQueryService ax = new ODataQueryService(new Uri(Link));
double test = double.NaN;
try
{
test = ax.InventTable.Where(X => X.InventTable_ItemId == "030001").Select(x => x.InventTable_Width).FirstOrDefault();
}
catch (Exception e)
{
Console.WriteLine(e);
}
返回错误:
System.Data.Services.Client.DataServiceQueryException: An error occurred while processing this request. ---> System.Data.Services.Client.DataServiceClientException: <?xml version="1.0" encoding="utf-8" standalone="yes"?>
<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<code></code>
<message xml:lang="da-DK">An error occurred while processing this request.</message>
</error>
at System.Data.Services.Client.QueryResult.ExecuteQuery()
at System.Data.Services.Client.DataServiceRequest.Execute[TElement](DataServiceContext context, QueryComponents queryComponents)
--- End of inner exception stack trace ---
at System.Data.Services.Client.DataServiceRequest.Execute[TElement](DataServiceContext context, QueryComponents queryComponents)
at System.Data.Services.Client.DataServiceQuery`1.Execute()
at System.Data.Services.Client.DataServiceQuery`1.GetEnumerator()
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
at System.Data.Services.Client.DataServiceQueryProvider.ReturnSingleton[TElement](Expression expression)
at System.Data.Services.Client.DataServiceQueryProvider.Execute[TResult](Expression expression)
at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable`1 source)
但是这个
ODataQueryService ax = new ODataQueryService(new Uri(Link));
double test = double.NaN;
try
{
test = ax.InventTable.AsEnumerable.Where(X => X.InventTable_ItemId == "030001").Select(x => x.InventTable_Width).FirstOrDefault();
}
catch (Exception e)
{
Console.WriteLine(e);
}
返回实际值,但加载整个表... 某种程度上可以避免这种情况,或者为什么我会首先遇到第一个错误?