操作而不是查询拦截器(WCF数据服务) [英] Operation instead of query interceptor (WCF Data Services)

查看:231
本文介绍了操作而不是查询拦截器(WCF数据服务)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读有关查询拦截器。我很失望,因为多数民众赞成更像是一个过滤器,而不是一个拦截器。换句话说,你可以eather包括记录或不包括他们。你是不是能够修改实例记录。



如果我想创建一个查询拦截我的实体用户然后我可以做这样的事情:

  [QueryInterceptor(用户)] //申请表的用户
公表达式来; Func键<使用者,布尔>> UsersOnRead()
{
返回卡斯特= GT; cust.IsDeleted ==虚假;
}



如果我不是创建操作: 注:非常重要,有运作名称就像实体名称,否则将无法正常工作

  [ WebGet] 
公开的IEnumerable<使用者>用户()
{
返回this.CurrentDataSource.Users.Where(X => x.IsDeleted ==假);
}



配售这种方法,而不是查询拦截让我服务的行为如出一辙。另外,我有更多的力量!正在采取这种方式更好的解决办法?


解决方案

我身边多了几分这个和的问题,一人分饰是导航性能赢得T进行过滤。比方说,你必须有一个链接到IEnumberable客户的



如果您



<$ P $的实体称为销售人员p> [QueryInterceptor(客户)] //只显示活跃客户
公共表达式来; Func键<客户,布尔>> ActiveCustomers()
{
返回卡斯特= GT; cust.IsDeleted ==虚假;
}



,当你查询你的OData源像WCFDataService.svc /销售人员

?$ =拓展客户结果客户将仍然有应用滤镜设置。



但这种

  [WebGet] 
公众的IQueryable<客户和GT;客户()
{
返回this.CurrentDataSource.Customers.Where(X => x.IsDeleted ==假);
}

在运行的OData查询像WCFDataService.svc /客户,你将有过滤列表在活跃的客户,但在运行此WCFDataService.svc /销售人员什么时候?$ =拓展客户,为客户将包括删除客户设置的结果。


I was reading about query interceptors. I was disappointed because thats more like a filter instead of an interceptor. In other words you can eather include records or not include them. You are not able to modify records for instance.

If I want to create a query interceptor for my entity Users I could then do something like:

[QueryInterceptor("Users")] // apply to table users
public Expression<Func<User, bool>> UsersOnRead()
{
    return cust => cust.IsDeleted == false;
}

What if I instead create the operation: NOTE IS VERY IMPORTANT TO HAVE THE OPERATION NAME JUST LIKE THE ENTITY NAME OTHERWISE IT WILL NOT WORK

[WebGet]
public IEnumerable<User> Users()
{                    
    return this.CurrentDataSource.Users.Where(x=>x.IsDeleted==false);
}

Placing this method instead of the query interceptor makes my service behave exactly the same. Plus I have more power! Is taking this approach a better solution?

解决方案

I played around a little more with this and one of the issues is navigation properties won't be filtered. Let's say you have an entity called SalesPeople that has a link into IEnumberable of Customers

If you do

[QueryInterceptor("Customers")] // only show active customers
public Expression<Func<Customers, bool>> ActiveCustomers()
{
    return cust => cust.IsDeleted == false;
}

when you query your OData feed like WCFDataService.svc/SalesPeople?$expand=Customers the results set for Customers will still have the filter applied.

But this

[WebGet]
public IQueryable<Customers> Customers()
{                    
    return this.CurrentDataSource.Customers.Where(x=>x.IsDeleted==false);
}

When running OData query like WCFDataService.svc/Customers you will have the filtered list on active customers, but when running this WCFDataService.svc/SalesPeople?$expand=Customers the results set for the Customers will include deleted customers.

这篇关于操作而不是查询拦截器(WCF数据服务)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆