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

发布于 2024-08-31 04:15:10 字数 1039 浏览 3 评论 0 原文

我刚刚读过“在 ADO.NET 数据服务中注入自定义逻辑”,我的下一个问题是,如何让 [WebGet] 方法显示在客户端中代理类?当然,我可以使用 WebClient 直接(RESTful)调用它,但我认为 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() 显示在我的客户端类定义中?

I've just read "Injecting Custom Logic in ADO.NET Data Services" and my next question is, How do you get your [WebGet] method to show up in the client-side proxy classes? Sure, I can call this directly (RESTfully) with, say, WebClient but I thought the strong typing features in ADO.NET Data Services would "hide" this from me auto-magically.

So here we have:

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

}

How can I get CustomersInCity() to show up in my client-side class defintions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

策马西风 2024-09-07 04:15:10

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

只需在链接后面写上您的方法名称
对于您的方法,它将是这样的...

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

When you see your Odata in browser, you will see link ...
e.g. http://localhost:1234/odataService.svc

just write your method name after the link
for your method it will be something like this...

http://localhost:1234/odataService.svc/CustomersInCity?city="London"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文