【问题标题】:WCF Data Service Method for Aggregation with filter使用过滤器进行聚合的 WCF 数据服务方法
【发布时间】:2011-12-04 08:01:33
【问题描述】:

我需要聚合我的 wcf 数据服务的一些数据,以便执行“月度报告”之类的操作。通过 odata 协议无法进行 Afaik 聚合。我想我必须为此实现自己的 WebGet 方法(或者还有其他可能性吗?)。我的第一枪是:

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

}

我想使用 odata 协议的 $filter 参数来过滤聚合。这可能吗?这是使用 WCF 数据服务进行聚合的正确方法吗?我很无知,找不到任何有用的信息。提前致谢...

【问题讨论】:

    标签: wcf wcf-data-services aggregation


    【解决方案1】:

    在重新考虑之后,我得出结论,最好和最简单的方法可能是数据库视图。这意味着我可以创建一个额外的实体来映射到视图,然后可以通过数据服务访问它。然而这给了我一个问题,因为视图没有主键......

    还有其他想法吗?

    更新:我通过为视图中的每一行生成一个 ID (Firebird) 解决了主键问题:

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

    但是,对于 wcf 数据服务的这个问题,似乎没有“干净”的解决方案?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多