使用SQL Server存储过程存储WCF休息请求数据

时间:2022-04-11 10:16:26

I have a simple interface in my WCF service with one method which gets a myRequest parameter

我的WCF服务中有一个简单的接口,其中一个方法获取myRequest参数

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.

当我从客户端发布数据时,内容类型是application / json,因此请求主体自动反序列化为myRequest对象。

myRequest is a WCF DataContract:

myRequest是一个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).

好的,现在我想将请求数据存储到我的本地SQL Server数据库中,为此我需要使用存储过程。我想将myRequest对象发送到SQL Server并让它处理插入/更新(我认为我必须保留2个表:人和手机)。

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 个解决方案

#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.

你无法将复杂的对象传递给数据库,如果使用CLR存储过程,旧的普通存储过程或其他东西,则无关紧要。

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).

您需要将请求转换为可以传递给db的内容。如果你知道如何在T-Sql中操作XML(这可能有点棘手),那么XML序列化是这项工作的理想选择。

I think abandoning the idea of using stored procedures and embracing something else (like EF) would be better for you.

我认为放弃使用存储过程和拥抱其他东西(如EF)的想法对你来说会更好。

#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.

你无法将复杂的对象传递给数据库,如果使用CLR存储过程,旧的普通存储过程或其他东西,则无关紧要。

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).

您需要将请求转换为可以传递给db的内容。如果你知道如何在T-Sql中操作XML(这可能有点棘手),那么XML序列化是这项工作的理想选择。

I think abandoning the idea of using stored procedures and embracing something else (like EF) would be better for you.

我认为放弃使用存储过程和拥抱其他东西(如EF)的想法对你来说会更好。