views:

56

answers:

1

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)
                 }) 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

A: 

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).

Vitek Karas MSFT
thanks Vitek, I did created a service operator on the server side, and It didn't work either. it says the same. Group by is not supported. Right now I am checking and it looks like I don't have a primary key in each table as it is required.
[WebGet] public IQueryable<DataSummary> GetTotals() { return (CurrentDataSource.Data.GroupBy(a => a.AccountID).Select(g => new DataSummary() { AccountType = "", AccountID = g.Key.Value, Value = g.Sum(p => (decimal)p.Value) } ) ); }
The support in service operations is limited by the provider you use under your WCF Data Service. Since you didn't mention which one it is, I can't comment on it.Anyway - even if it will work, the fact that are creating an arbitrary new type will not work, since service operations can only return enumeration of already defined entity or complex types. You would have to return either a primitive value or already defined type.Also note, that currently the client doesn't support parsing responses from service operations which return enumeration of complex types.
Vitek Karas MSFT
so I have to create an entity for every query that I make??? I think that very funny.... I am going to study that part, i am working with sql server. thanks a lot.