ssmsnet
ssmsnet

Reputation: 2306

WCF Data Services ODATA

I am working on WCF Data Services. I have a function in my service which adds a record into a table in SQL DB and return the ID of the Inserted record.

I Used to Pass the values to be inserted in the form of Parameters to the Function.

For Example

 public int Add(string Name, string Password)
 {
      // Here I will Add the record and return the ID of the record added in DB
 }

But I dont want to do this way of passing in the form of parameters.

I want to pass the object directly.

Like

public int Add(User user)
{
    // Here I will Add the record and return the ID of the record added in DB
}

I wrote the function like above in my services and my services project is successfull. When I update my ServiceRefrences I get Error.

It says only primitive types are supported. Is there any work around this problem.

Thanks For Your Time in Answering my Question.

Upvotes: 0

Views: 448

Answers (1)

Vitek Karas MSFT
Vitek Karas MSFT

Reputation: 13320

WCF Data Services (and OData protocol for that matter) only support passing primitive values as parameters to service operations.

The OData way of adding a new entity into an entity set is to send a POST with the entity in the payload to the entity set URL. In the WCF DS Service this will get translated into several calls to the IUpdatable interface on your context.

Upvotes: 1

Related Questions