Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8394899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:10:14+00:00 2026-06-09T20:10:14+00:00

We are using DTOs as Data Contracts in our WCF web service. The purpose

  • 0

We are using DTOs as Data Contracts in our WCF web service. The purpose for these DTOs is to expose only the information that is relevant for a specific API method.

What I am seeking from you guys is some advise on the best practices here.

For example, consider the following simple model:

class Order
{
    int CreatedBy { get; set; }
    DateTime CreatedOn { get; set; }
    string Description { get; set; }
    int Id { get; set; }
    string Name { get; set; }
}

Assuming our API allows a consumer to Create, Update and Get an Order, we have created the following DTOs. DataMember and DataContract attributes are eliminated for simplicity.

Create method: A user cannot specify the Id and CreatedOn properties, so the DTO looks like this:

class CreateOrderData
{
    int CreatedBy { get; set; }
    string Description { get; set; }
    string Name { get; set; }
}

Update method: A user cannot specify the Id, CreatedOn and CreatedBy properties, so the DTO looks like this:

class UpdateOrderData
{
    string Description { get; set; }
    string Name { get; set; }
}

Get method: A user should be able to see everything for the Order, so the DTO looks like this:

class OrderData
{
    int CreatedBy { get; set; }
    DateTime CreatedOn { get; set; }
    string Description { get; set; }
    int Id { get; set; }
    string Name { get; set; }
}

So here are my questions:

  • Assuming there are more properties in Order model and lot of those properties are shared between “Create” and “Update” DTOs, does it make sense to have these classes extend from a common base class? If yes, should the “Get” DTO (OrderData) also extend from that class? If we do that, doesn’t it leave these DTOs too dependent on each other?

  • If all the properties are common between “Create” and “Update” DTOs, should we still create two different DTOs? If yes, why? If not, (this is just a naming question now) what should the “CreateOrUpdate” DTO be called so that the name is obviously different from the “Get” DTO?

  • Is it OK to suffix all the DTOs with something like “Data” or “DataObject” or “Dto”?

  • Are we on the right track here? If not, how can be make this design better?

Update:

I think I don’t like the inheritance in DTOs because the base class will also be exposed in the WSDL and the client will be able to see it and instantiate it which seems dirty to me (see this: WCF Serialization with object inheritance?). How about using Interfaces in DTOs to enforce common properties instead of inheritance? Since DTOs should not have any behavior in them, we are not losing much by replacing inheritance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T20:10:15+00:00Added an answer on June 9, 2026 at 8:10 pm

    Since this is a lot about personal preferences, I would do this ..

    1. I would not create a common base class since that would not adhere to L in SOLID. If you are concerned about DRY, then you could create a aggregation instead.

    2. If all properties are common, then it just makes sense to create a Save that takes that object, the order Dto class will have a key property(ies) that would indicate if its an existing order or not.

    3. I would suffix all with Dto, because a lot of Dto class names are same as domain classes, they get confusing since they will exist in the same method together. Then you can decorate your Dtos with DataContract(Name=”Order”, Namespace=”htp://yourdomain/..”]. This way they will be exposed to outside world according to your own preference.

    I have been in multiple projects that use the same general architecture, i generally use AutoMapper to map dtos to domain. It has worked great for me !

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am putting together a WCF Data Service for PatientEntities using Entity Framework. My
I am using DTOs in my code to transfer data between layers. I have
I am currently using the same C# DTOs to pull data out of CouchDB,
I am writing an application that is consuming an in-house WCF-based REST service and
I've read that one of primary reasons for using DTOs is to minimize roundtrips
I have an MVC2 n-tier application (DAL, Domain, Service, MVC web) using a DDD
I have my service layer, entities and DTOS in a separeted assembly called CCL.Data
I have a REST-style web application that uses EF code first. I'm using AutoMapper
We're about to set off our first larger WCF project, and we're having some
All, My typical approach for a medium sized WCF service would be something like:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.