I have one table with 20 columns, I want only display this data on UI (not add/edit/delete). I want to know, where is appropriate place to create DTO class for this table, in DAL project or in Web project?
3 Answers
You can create DTO's in the web project, map the entity to it, and have the domain service call return it. You could also just return the entity and mark the Properties you don't want displayed with [Display(AutoGenerated = False)].

- 9,429
- 4
- 30
- 44
If you are using LINQ to Entities or LINQ to SQL, you could use projection to limit what is returned from the WCF service request and work with an anonymous type. Use the LINQ select method. Then you wouldn't have to create a DTO object.
If the UI you mentioned is Silverlight, WCF Data Services (EDIT: and WCF RIA Services does not) support projection across a service.
LINQ example:
context.Displays
.OrderBy(d => d.Title)
.Select (
d =>
new
{
Title = d.Title
})
Julie Lerman says to use the QueryView in an MSDN Magazine article. That might be the solution.

- 8,102
- 9
- 56
- 91
-
If I work with anonymous type, how can I return that object to client. (I'm working with Silverlight and WCF RIA) – Anonymous Mar 16 '11 at 08:57
-
I know that WCF Data services does work with projection, but after digging some more into WCF RIA services I found that it does not (I apologize). See this question: http://stackoverflow.com/questions/5176960/dynamic-query-with-wcf-ria-services – AlignedDev Mar 16 '11 at 13:42
If you only wants to show data, the better approach would be the create a View and directly get it on Client Side. This will be much more cleaner and easier.

- 1,289
- 13
- 25