简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM