472,968 Members | 1,725 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,968 software developers and data experts.

Data transfer objects in C#

Hi

I am learning DTO and wrote a dto for my "Product" class. I want to know
whether I am following the right method ? Here is my code

class Product
{
internal Product(ProductItem item)
{
this.Name = item.Name;
}

public string Name
{
get;set;
}

public static Product FromId(int productId)
{
ProductDAL data = new ProductDAL();
ProductItem item = data.GetProductFromId(productId);
return ProductFactory.CreateProduct(item);
}

public void Save()
{
ProductDAL data = new ProductDAL();
ProductItem item = new ProductItem(this.Name);
data.SaveDetails(item);
}

}

static class ProductFactory
{
public static CreateProduct(ProductItem item)
{
Product product = new Product(item);
return product;
}
}

// DTO class
class ProductItem
{
public ProductItem(string name)
{
this.Name = name;
}

public string Name
{
get;set;
}
}

Do you write any methods in the DTO class ? Or only some getters and
setters ?

Thanks
Jun 27 '08 #1
3 4413
jj
Hello Navaneet, I'll put in my 2 cents..

DTOs are strictly used for TRANSFERRING data. Think of it as a data
structure. The code for fetching or saving data should not be in a
DTO. It should be in DAL objects, and invoked from BLL objects.

Regards,
Jim
Jun 27 '08 #2
Hi Jim,

Thanks for replying me. I don't have Save functionality in DTO class.
"ProductItem" is the DTO class which contains only the data structure. So is
this correct approach ?

"jj" wrote:
Hello Navaneet, I'll put in my 2 cents..

DTOs are strictly used for TRANSFERRING data. Think of it as a data
structure. The code for fetching or saving data should not be in a
DTO. It should be in DAL objects, and invoked from BLL objects.

Regards,
Jim
Jun 27 '08 #3
jj
Hello Navaneet,

Your ProductItem class is a DTO. there is nothing wrong with it. Just
remember to mark your DTO classes as serializable if you want to send
them using web services or remoting. I know you know about this, but
just a reminder.

Regards,
Jim
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Arnnei | last post by:
The Transfer method allows you to transfer from inside one ASP page to another ASP page Is there a similar thing - The Transfer method taht allows you to transfer from inside one ASP page to a...
10
by: GreggTB | last post by:
I've got an page (LOGIN.ASPX) that receives the user's login information. During the page load, it checks the credentials against a database and, if validation is successful, creates an instance of...
1
by: ads | last post by:
how do i transfer database objects such as tables and sp to a database file in just clicks of a mouse? Originally we are using sql server 2000 as our data storage for a website but since the...
0
Frinavale
by: Frinavale | last post by:
Platform: WindowsXP and IIS Language: Asp .NET (using Visual Basic back end) I'm not sure if anyone will be able to understand my code because its written using ASPX and Visual Basic back end. ...
4
by: Mark Olbert | last post by:
I'm looking for help in getting the Transfer Sql Server Objects task to work. The goal is to transfer the tables, views, sprocs, udfs from a SqlServer 2000 database to a Sql Server 2005 database. ...
12
by: joaotsetsemoita | last post by:
Hello everyone, im completly new to vb.net and I was assigned to do a simple piece of software that just had to select from um db in a MS access data base and insert into a SQL server Database....
4
by: Andrew Jackson | last post by:
I am writing a newsgroup client. I have the protocol figured out. But I get slow transfer speeds off any of the network objects read the data from For example one of the commands for a news...
1
by: Daniel | last post by:
Hello, I've been building a system that has need to send object data across the network. The approach I've taken has been to build Data Transfer Objects, which just contain the attributes of...
0
by: Jean-Paul Calderone | last post by:
On Thu, 2 Oct 2008 14:45:12 -0700 (PDT), Daniel <daniel.watrous@gmail.comwrote: You might be interested in Perspective Broker: ...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.