locked
Parameter WCF-Services & Entity Framework RRS feed

  • Question

  • Hi,

    I'm a little bit in trouble while doing WCF-Service design.

    Simple example:

    CustomerService
     - AddCustomer(Customer c);

    Customer is a Entity (defined using EF).

    The client creates the new Customer and the Service is doing the insert Task:
    var c = new Customer { Name="x", City="y" };
    var client = new CustomerServiceClient();
    client.AddCustomer(c);

    This should work fine. What I have learned in the past is that the real world looks a litte bit diffrent.

    For example:
    Customer have CustomerCategory (=A / B / C e.g.1:n relation) and Customer have to be added to a SalesPerson.

    When I now want to create the stuff as a service than I'm a litte bit in trouble. My client knows that the SalesPerson have ID = 1 and Category have ID =5.
    How should my Service-Method look like?
    void AddCustomer(int CategoryID, ind SalesPersonID, Customer c);
     or should I use a DTO which include these properties?
    void AddCustomer(CustomerDTO c); (=CustomerDTO have a Property for CategoryID and SalesPersonID)
     or any other idea?

    If I use a DTO (which diffrent data & Properties as the Entity itself) I have to do a lot of manual mapping.
    Wednesday, October 14, 2009 10:16 PM

All replies

  • There is no free lunch, I believe the DTO approach is the correct one.
    Wednesday, October 14, 2009 10:25 PM
  • I would take a look at .NET RIA Services , as well.  Even if you're not workign with Silverlight, there's some very good guidance on pushing entites across tiers in their samples.

    Reed Copsey, Jr. - http://reedcopsey.com
    Wednesday, October 14, 2009 10:59 PM
  • Hi,

    Is your scenerio where your ASP.Net form needs to make multiple web service calls to complete an single user request?? DTO is the way to go. On the use of DTO.

    The design of the DTO is very critical , you need not create new classe for each DTO bcos the Dataset class of .Net is generic enough to handle multiple DTO's.

    Is your presentation Silver light or AJAX based, then have look at RIA service pattern.

    Though i have not implemented the same
    Thursday, October 15, 2009 4:14 AM