简体   繁体   中英

How to create IQueryable results using Entity Framework complex types

I have the following Service Operation where DataDTO is a complex type (added via Entity Framework Model Browser):

[WebGet]
public IQueryable<DataDTO> GetInformation(string id)
{
 var resultList= (from data in context.Data
                  where data.ID ==id
                  select new
                  {
                   DataID = data.ID,
                   Name = data.Name,
                   Group = data.Group
                  })
               .ToList()
               .Select(item =>
                  new DataDTO
                  {
                    ID = item.ID,
                    Name= item.Name,
                    Group = item.Group
                  });
 return resultList.AsQueryable();
}

When I access it with a client, I get an exception:

Query options $orderby, $inlinecount, $skip and $top cannot be applied to the requested resource.

So adding AsQueryable does not solve the issue.

How should I modify the query to return IQueryable considering the usage of the complex type?

Solution 1:Add the [SingleResult] attribute on the service operation method to let WCF DS know that the IQueryable is only gonna return a single value

Solution 2:WCF OData service methods do not support query options.Try disable paging for your data source by setting the DataSource.paginate option to false

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM