开发者

Group by is not working on WCF Data Services

I have this code,

Data Summary is a class, it is not an entity. I use it for the anonymous type on "select new"

public class DataSummary
{
    public DataSummary()
    {
    }

    public int AccountID
    {
        get; set;
    }

    public decimal Total
    {
        get; set;
    }
}

then I have this query

        DateTime date1 = new DateTime(2003, 1, 1);
        DateTime date2 = new DateTime(2011, 1, 1);


        InitializeComponent();

        var query = (from d in svc.Data
                 where d.Date >= date1 && d.Date <= date2
                 group d by d.AccountID into g
                 orderby g.Key
                 select new DataSummary()
                 {
                     AccountID = g.Key.Value,
                     Total = g.Sum(d => (decimal) d.Value开发者_JS百科)
                 }) as DataServiceQuery<DataSummary>;


        query.BeginExecute(new AsyncCallback(r =>
        {
            try
            {
                this.grid.ItemsSource = query.EndExecute(r).ToList();
            }
            catch (Exception ex)
            {
                string message = ex.Message;
            }
        }), null);

when I run the query, It says that group by it is not supported. I have seen many question about WCF data services that use group by. anybody know what is going on???

When I put the code in the server side, it gives me an error too. I have tried to retrieve information with datasummary without the group by and it works. so I am out of options

Thanks in advance


Group by is not supported by WCF Data Services client library because there's no support for such operator in the URL query language. I wonder where have you seen it mentioned that it actually works.

You can either download all the entities in question to the client and perform the group by on the client in memory, or you can create a service operation on the server for this purpose. In case you choose the service operation approach, the ability to run group by queries is up to the provider you use for the data service (for example EF should be able to handle that).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜