问题
I have a simple interface in my WCF service with one method which gets a myRequest
parameter
public interface IService
{
[OperationContract]
string MyOperation(myRequest request);
}
When I'm posting the data from the client, the content type is application/json
, so the request body auto deserialise into myRequest
object.
myRequest
is a WCF DataContract
:
[DataContract]
public class myRequest
{
string id;
string name;
List<Phone> phones
[DataMember]
public string Name { get; set; }
[DataMember]
public string ID { get; set; }
[DataMember]
public List<Phone> Phones { get; set; }
}
and the Phone
class
public class Phone
{
public string Number { get; set; }
public string Type { get; set; }
public override string ToString()
{
return "[" + Number + "," + Type + "]";
}
}
Ok, so now I would like to store the request data into my local SQL Server database and for that I need to use stored procedures. I want to send the myRequest
object to SQL Server and let it deal with insert/update (I think what I will have to keep 2 tables: people and phones).
I don't have to much background about stored procedures but I will great to get from you guys the right approach to solve this.
Thanks.
回答1:
There's no way you can pass a complex object to the db, and it does not matter if you use a CLR stored proc, an old plain stored proc or something else.
You'll need to transform your request into something that can be passed to the db. An XML serialisation is a good candidate for the job, if you know how to manipulate XML in T-Sql (which could be a little tricky).
I think abandoning the idea of using stored procedures and embracing something else (like EF) would be better for you.
来源:https://stackoverflow.com/questions/30128039/storing-wcf-rest-request-data-with-sql-server-stored-procedure