Object for WCF datacontract

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

Do I need to write my own datacontract to return the extracted 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 };
+3
source share
1 answer

Good practice is to separate the DTO from the service objects. What you need to do is create a service employee class and implement converter methods from / to your DTO employee.

Then your service operation returns a list of service employees, not a DTO list.

As a starter:

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

, :

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();
}
+4

Source: https://habr.com/ru/post/1780984/


All Articles