0

我有将 WCF DataServices 与 EntityFramework 一起使用的 ac# 应用程序。

似乎一切正常,但现在我需要使用存储过程实现自定义插入。

我试图在网上找到任何帮助,但似乎没有任何帮助。

我有我的数据服务:

[MessageInspectorBehavior]
    public class Security : DataService<VisitAwareContext>
    {
        // This method is called only once to initialize service-wide policies.
        public static void InitializeService(DataServiceConfiguration config)
        {
            // TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
            // Examples:
            config.SetEntitySetAccessRule("SecurityUsers", EntitySetRights.All);
            config.SetEntitySetAccessRule("Sessions", EntitySetRights.All);
            // config.SetServiceOperationAccessRule("MyServiceOperation", ServiceOperationRights.All);
            config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
            // Other configuration here...
            config.UseVerboseErrors = true; // TODO - Remove for production?
        }

[WebGet]
        public bool CustomInsert(string customField1, string customField2)
        {
            // here I need to call my stored procedure and pass the fields....

            return true;
        }
}

有没有办法做到这一点?或者有人可以推荐我一个解决方案?

我知道您不能只使用一种服务器-客户端数据技术,例如 WCF DataServices,我可以为这些场景添加另一种 WCF ADO.NET 方法,但我想暂时使用 EF + WCF Data Services。

非常感谢。

4

2 回答 2

1

OData 操作与 WCF 数据服务“服务操作”一起使用。如 MSDN 文章中所述,您可以WebInvoke在数据服务类中的方法上使用 WCF 属性(尊重属性给出的约束)。

在该方法中,您可以使用CurrentDataSource数据服务的属性(从其基础DataService类继承)来检索实体框架DbContext

从那里,您可以在 Stack Overflow 上搜索如何使用 Entity Framework 调用存储过程(或者更好;当然,请阅读精美的手册)。

于 2013-10-02T17:17:33.390 回答
0

使用 [WebInvoke] 代替 [WebGet] 属性。这样,您应该能够使用 POST 而不是来自客户端的 GET 来调用服务操作。除此之外,您所拥有的似乎是正确的。

谢谢普拉蒂克

于 2013-10-01T18:36:24.497 回答