Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 datacontract 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 };
like image 626
Hukam Avatar asked Dec 01 '25 05:12

Hukam


1 Answers

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();
}
like image 162
vc 74 Avatar answered Dec 03 '25 19:12

vc 74



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!