存储与SQL Server存储过程WCF剩下的请求数据

问题描述:

我在我的一个方法,得到了 myRequest 参数WCF服务的简单界面

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);
}

当我张贴来自客户端的数据,内容类型是应用程序/ JSON ,所以请求主体的汽车deserialise到 myRequest 对象。

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 是一个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; }
}

电话

public class Phone
{
    public string Number { get; set; }
    public string Type { get; set; }

    public override string ToString()
    {
        return "[" + Number + "," + Type + "]";
    }
}

好了,现在我想请求数据存储到我的本地SQL Server数据库,并为我需要使用存储过程。我想了 myRequest 对象发送到SQL Server,让它与插入/更新处理(我想我将不得不继续2表:个人和电话)。

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.

感谢。

有没有办法可以传递一个复杂的对象的数据库,如果你使用CLR存储过程也不要紧,一个老平原存储PROC 的或别的东西。

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.

您需要将您的请求转换成可以传递到数据库的东西。一个XML序列化是一个很好的候选人的工作,如果你知道如何操作XML在T-SQL(这可能是一个有点棘手)。

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

我想放弃了使用存储过程和拥抱别的东西(如EF)将是你最好的主意。

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