使用过滤器进行聚合的 WCF 数据服务方法
我需要聚合 WCF 数据服务的一些数据,以便执行“月度报告”之类的操作。 Afaik 聚合不可能通过 odata 协议实现。我想我必须为此实现我自己的 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 数据服务进行聚合的正确方法吗?我对此一无所知,找不到任何有用的信息。提前致谢...
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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过重新思考后,我得出的结论是,最好和最简单的方法可能是数据库视图。这意味着我可以创建一个映射到视图的额外实体,然后可以通过数据服务进行访问。然而,这给了我一个问题,因为视图没有主键......
还有其他想法吗?
更新:我通过为视图中的每一行生成一个 ID(Firebird)解决了主键问题:
但是,wcf 数据服务似乎没有“干净”的解决方案来解决此问题?
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):
However it seems there is no "clean" solution for this problem with wcf data services?