473,890 Members | 1,423 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(Product Item item)
{
this.Name = item.Name;
}

public string Name
{
get;set;
}

public static Product FromId(int productId)
{
ProductDAL data = new ProductDAL();
ProductItem item = data.GetProduct FromId(productI d);
return ProductFactory. CreateProduct(i tem);
}

public void Save()
{
ProductDAL data = new ProductDAL();
ProductItem item = new ProductItem(thi s.Name);
data.SaveDetail s(item);
}

}

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

// DTO class
class ProductItem
{
public ProductItem(str ing 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 4440
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.
"ProductIte m" 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
1448
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 DLL.
10
12225
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 an object that stores the user's basic profile data (username, user type, associated sales region, etc.). I've been taking this user info and placing it in the Session object like so... Session = user;
1
1306
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 website needs to be installable,i decided to make a database file as the storage which will automatically be included in the installer package.Now how do i transfer database objects to that database file?What i can only see are facilities such as add...
0
1619
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. My problem is mostly understanding the ASP part and Server.Transfer oddities I'm experiencing. I have posted before about this project's problems but since I have recoded everything to implement Server.Transfer, figured its probably best to start a...
4
3238
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. When I set the task up and run it, it fails complaining about an invalid foreign key relation. The relation in question is valid, and used in the current production environment under SS2000, so I think the real problem is something else. I've seen...
12
2033
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. The structure tables are exactly the same so there's no need in data conversation. My idea was to fill a datatable with the results from my oledbdataadapter and then use that dataset to update on my sqldataadapterm, however I cant find the way...
4
7596
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 client to use is "XOVER articlenumber-" This return string after string of all the news articles from article number on.... Another newsclient, i wont name names, pulls data down just fine. Using a
1
4402
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 the objects, and to pickle them and send them over a socket connection. As I get deeper this is a bit problematic, and so I was wondering if there is a package or framework that is already designed to do this?
0
931
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: http://twistedmatrix.com/projects/core/documentation/howto/pb-intro.html Jean-Paul
0
9980
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9829
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10926
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10468
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9643
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7172
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5856
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4683
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3287
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.