开发者

Problem with WCF Data service exposing custom partial methods of EF4 model

I am exploring the idea of implementing a web service api using WCF Data Services and EF4. Realizing that some operations require complex business logic, I decided to create a partial class the same name as the main EF data context partial class and implement additional methods there to handle the more complex business logic. When the EF context object is used directly, the additional method shows up (via intellisense) and works properly. When the EF classes are exposed through a WCF Data Service and a Service Reference is created and consumed in another project, the new method does not show up in intellisense or in the generated Service.cs file (of course, I updated the reference and even deleted it and re-added it). The native data methods (i.e. context.AddObject() and context.AddToPeople()) work properly, but the new method isn't even available.

My EF classes look something like this:

namespace PeopleModel
{
    //EF generated class
    public partial class PeopleEntities : ObjectContext
    {
        //Constructors here

        //Partial Methods here
开发者_Python百科
        //etc....
    }

    //Entity classes here

    //My added partial class
    public partial class PeopleEntities
    {
        public void AddPerson(Person person)
        {
            base.AddObject("People", person);
        }       
    }   
}

There's nothing special about the .svc file. The Reference.cs file containing the auto generated proxy classes do not have the new "AddPerson()" method.

My questions are: 1. Any idea why the web service doesn't see the added partial class, but when directly using the EF objects the method is there and works properly? 2. Is using a partial class with additional methods a good solution to the problem of handling complex business rules with an EF generated model?

I like the idea of letting the oData framework provide a querying mechanism on the exposed data objects and the fact that you can have a restful web service with some of the benefits of SOAP.


Service operations are only recognized if they are present on the class which derives from DataService. The WCF Data Service will not look into the context class for these. Also note that methods are not exposed by default, you need to attribute them with either WebGet or WebInvoke and allow access to them in your InitializeService implementation. http://msdn.microsoft.com/en-us/library/cc668788.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜