ADO.NET数据服务中的自定义逻辑和代理类

时间:2010-04-29 21:50:52

标签: ado.net odata

我刚刚阅读了“Injecting Custom Logic in ADO.NET Data Services”,我的下一个问题是,如何让您的[WebGet]方法显示在客户端代理类中?当然,我可以直接(RESTfully)用WebClient来调用它,但我认为ADO.NET数据服务中的强类型功能会自动“隐藏”这一点。

所以我们在这里:

public class MyService : DataService<MyDataSource>
{
    // This method is called only once to initialize service-wide policies.
    public static void InitializeService(IDataServiceConfiguration config)
    {
        config.SetEntitySetAccessRule("Customers", EntitySetRights.AllRead);
        config.SetServiceOperationAccessRule("CustomersInCity", ServiceOperationRights.All);
    }

    [WebGet]
    public IQueryable<MyDataSource.Customers> CustomersInCity(string city)
    {
        return from c in this.CurrentDataSource.Customers
               where c.City == city
               select c;
    } 

}

如何让CustomersInCity()出现在我的客户端类定义中?

1 个答案:

答案 0 :(得分:1)

当您在浏览器中看到Odata时,您会看到链接... 例如http://localhost:1234/odataService.svc

只需在链接后写下您的方法名称即可 对于你的方法,它将是这样的......

http://localhost:1234/odataService.svc/CustomersInCity?city= “伦敦”