WCF Data Service and Inserting new Records that use Inheritence RRS feed

  • Question

  • Hi,

    I have a WCF data service that hooks into an ObjectContext, which in turn has two entities. Foo and Bar (which extends Foo).  The ObjectContext has an accessor for Foo's only since Bar is a child object of Foo.

    When I try to POST to insert a new Foo using JSON and the url  http://localhost:888/myservice.svc/Foos , and using the following json content " { id: 0, someField: 'some value' } ", I get the following error:


    "error": {
    "code": "", "message": {
    "lang": "en-US", "value": "Error processing request stream. Type information must be specified for types that take part in inheritance."

    can someone please help?



    • Moved by Alan_chenModerator Monday, December 26, 2011 5:27 AM (From:ADO.NET Entity Framework and LINQ to Entities)
    Friday, December 23, 2011 5:27 PM

All replies

  • Hi,

    If the entity set has inheritance you must specify the type of the entity to insert (otherwise WCF DS would not know wether to create Foo or Bar). To do that use payload like:

    { __metadata: { type: "TypeName" }, id: 0, someField: "some value" }

    Replace the TypeName with the full name of your entity type you want to insert. That is the Namespace.Name (usually). The easiest way to tell the namespace is either from the $metadata CSDL, or by requesting already existing instance (GET myservice.svc/Foos) and the response will have type names (in ATOM it's in a category element, in JSON it's in the __metadata property).


    Vitek Karas [MSFT]
    Wednesday, December 28, 2011 8:42 AM
  • Hy,

    If you can put yur serilizationMode to unidirectional.

    Best regards,

    So B
    Thursday, January 5, 2012 8:55 AM