473,395 Members | 2,079 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 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 4423
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: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.