我想创建一个WCF服务,使用Entity Framework调用SQL Server中的存储过程,并将结果集返回给浏览器.
我使用EF中的函数import导入了存储过程,并构建了一个复杂类型.
似乎EF中的复杂类型无法序列化并且可以重新返回.我完成这项工作的唯一方法是创建一个具体的类,并从EF返回的复杂类型构建它.这有效,但这意味着如果我有30个存储过程,我需要创建30个具体的类,这有点痛苦.
有一个更好的方法吗?
WCF合同:
[ServiceContract]
public interface IService1
{
[OperationContract,WebGet,XmlSerializerFormat]
List<People> usp_GetPeople();
}
Run Code Online (Sandbox Code Playgroud)
需要为每个过程创建具体类:
public class People
{
public int person_id;
public string last_name;
public string first_name;
public string street_addr;
public string state_code;
public string postal_code;
public People(int person_id, string last_name, string first_name, string street_addr, string state_code, string postal_code)
{
this.person_id = person_id;
this.last_name = last_name;
this.street_addr = street_addr;
this.state_code = state_code;
this.postal_code = postal_code;
}
public People() { }
}
Run Code Online (Sandbox Code Playgroud)
WCF服务:
public class Service1 : IService1 …Run Code Online (Sandbox Code Playgroud)