QueryInterceptorAttribute 类

方法上的 QueryInterceptorAttribute 在指定实体集上将其批注为查询侦听器。

继承层次结构

System.Object
  System.Attribute
    System.Data.Services.QueryInterceptorAttribute

命名空间:  System.Data.Services
程序集:  Microsoft.Data.Services(在 Microsoft.Data.Services.dll 中)

语法

声明
<AttributeUsageAttribute(AttributeTargets.Method, AllowMultiple := True, Inherited := True)> _
Public NotInheritable Class QueryInterceptorAttribute _
    Inherits Attribute
用法
Dim instance As QueryInterceptorAttribute
[AttributeUsageAttribute(AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
public sealed class QueryInterceptorAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Method, AllowMultiple = true, Inherited = true)]
public ref class QueryInterceptorAttribute sealed : public Attribute
[<SealedAttribute>]
[<AttributeUsageAttribute(AttributeTargets.Method, AllowMultiple = true, Inherited = true)>]
type QueryInterceptorAttribute =  
    class
        inherit Attribute
    end
public final class QueryInterceptorAttribute extends Attribute

QueryInterceptorAttribute 类型公开以下成员。

构造函数

  名称 说明
公共方法 QueryInterceptorAttribute 针对 entitySetName 参数指定的实体集,初始化 QueryInterceptorAttribute 类的新实例。

页首

属性

  名称 说明
公共属性 EntitySetName 获取包含要对其应用侦听器的实体的实体集的名称。
公共属性 TypeId (从 Attribute 继承。)

页首

方法

  名称 说明
公共方法 Equals (从 Attribute 继承。)
受保护方法 Finalize (从 Object 继承。)
公共方法 GetHashCode (从 Attribute 继承。)
公共方法 GetType (从 Object 继承。)
公共方法 IsDefaultAttribute (从 Attribute 继承。)
公共方法 Match (从 Attribute 继承。)
受保护方法 MemberwiseClone (从 Object 继承。)
公共方法 ToString (从 Object 继承。)

页首

显式接口实现

  名称 说明
显式接口实现私有方法 _Attribute.GetIDsOfNames (从 Attribute 继承。)
显式接口实现私有方法 _Attribute.GetTypeInfo (从 Attribute 继承。)
显式接口实现私有方法 _Attribute.GetTypeInfoCount (从 Attribute 继承。)
显式接口实现私有方法 _Attribute.Invoke (从 Attribute 继承。)

页首

注释

实体集级别的授权和验证由 QueryInterceptorAttribute 批注的方法实现。 WCF 数据服务 不实施安全策略,但提供服务开发人员编写自己的安全规则和业务验证所需的基础设施。

实体集访问控制和验证通过在查询操作中撰写查询启用。 若要控制基于实体的访问,请根据以下规则实现每实体一个方法设置:

该方法必须具有公共范围以及用 QueryInterceptorAttribute 添加批注,并以实体集的名称作为参数。

该方法不接受任何参数。

该方法必须返回 Expression<Func<T, bool>> 类型的表达式,是将组成实体集的筛选器。

示例

下面的示例控制对 Customers 实体集的访问。 每个 Customer 都只能看到与该 Customer 相关联的 Orders。

[QueryInterceptor("Orders")]
public Expression<Func<Order, bool>> FilterOrders() 
{
    return o => o.Customer.Name == /* Current principal name. */;
} 
 
// Insures that the user accessing the customer(s) has the appropriate
// rights as defined in the QueryRules object to access the customer
// resource(s).
 
[QueryInterceptor ("Customers")]
public Expression<Func<Customer, bool>> FilterCustomers() 
{
  return c => c.Name == /* Current principal name. */ &&
              this.CurrentDataSource.QueryRules.Contains(
                rule => rule.Name == c.Name &&
                        rule.CustomerAllowedToQuery == true
              );
}

线程安全

此类型的任何公共 static(在 Visual Basic 中为 Shared) 成员都是线程安全的。不保证所有实例成员都是线程安全的。

请参阅

参考

System.Data.Services 命名空间