开发者

WCF Data Service Method for Aggregation with filter

开发者 https://www.devze.com 2023-04-11 17:32 出处:网络
I need to aggreate some data of my wcf data service in order do something like a \"monthly report\". Afaik aggregation is not possible via the odata protocol. I guess I have to implement my own WebGet

I need to aggreate some data of my wcf data service in order do something like a "monthly report". Afaik aggregation is not possible via the odata protocol. I guess I have to implement my own WebGet method for this (or is there an other possibility?). My first shot would be:

[ServiceBehavior(AddressFilterMode = AddressFilterMode.Any, UseSynchronizationContext = false)]
class MyDataService : DataService<MyContext>
{
    public static void InitializeService(DataServiceConfiguration config)
    {
        config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;

        config.SetEntitySetAccessRule("*", EntitySetRights.All);
        config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
        config.UseVerboseErrors = true;
    }

    [WebGet]
    public int SumColumnOfMyTable()
    {
        // return here the aggregated data with the usage of the odata $filter param
    }

}

I want to use the $filter param of the odata protocol to filter the aggreagtion. Is this possible? Is this the right way to do aggregation with WCF Data Services? I'm quite clueless and can't find any开发者_开发问答 useful information about that. Thanks in Advance...


After rethinking this I came to the conclusion that the best and easiest way would probably be a database view. This means I could create an extra Entity that maps to the view and that then can be accessed via the data service. However this gives me an issue, because the view has no primary key...

Any other ideas?

UPDATE: I resolved the primary key issue by genarating an ID for each row in the view (Firebird):

coalesce(cast(rdb$get_context('USER_TRANSACTION', 'row#') as integer), 0) + 1 as ID

However it seems there is no "clean" solution for this problem with wcf data services?

0

精彩评论

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

关注公众号