开发者

Entity to WCF datacontract

I am using Enity Framework to fetch data from my database. In WCF, my method has a return type of List<EmployeeTable>. But I can't test my service in WCF test client.

Do I need to write my custom datac开发者_JAVA百科ontract to return the fetched data.

Edit:

How can I handle this case:

var query = from c in customers
            join o in orders on c.ID equals o.ID
            select new { c.Name, o.Product };


It's good practice to separate the DTOs from the service entities What you'll need to do is create a service employee class and implement converter methods from/to your employee DTO.

Then have your service operation return a list of service employees rather than list of DTOs.

As a starter:

public static Service.Employee ToServiceEntity(Data.Employee dataEmployee)
{
    Service.Employee result = new Service.Employee();
    result.FirstName = dataEmployee.FirstName;
    ...
    return result;
}

and the method implementing your operation contract:

public List<Service.Employee> GetEmployees(...)
{
  IEnumerable<Data.Employee> dataEmployees = // Retrieve employees from data repository
  var serviceEmployees = dataEmployees.Select(dataEmployee => EntityConverter.ToServiceEntity(dataEmployee°);

  return serviceEmployees.ToList();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜