473,574 Members | 3,158 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Design Question About Passing Entity Objects

Hello,

If I have a few simple classes to represent Entities such as Customers and
Orders.

What is the proper way to pass information to the Data Access Layer?

1) Pass the actual ENTITY to the Data Access Layer method
-or-
2) Pass some kind of a unique id to the Data Access Layer method

For example, how should the DAL.FindCustome r method be implemented:

1) public static Customer FindCustomer(Cu stomer customer);
-or-
2) public static Customer FindCustomer(in t customerID);

If I need to find a customer either by an ID or by the username, what is the
proper way:

1) public static Customer FindCustomer(Cu stomer customer); // and the method
will look at the filled-in properties of Customer and determine what to
search by
-or-
2) public static Customer FindCustomerByI D(int customerID); and public
static Customer FindCustomerByU sername(string username);

I understand that passing the ENTITY is more expensive than passing a single
unique key. However, does the abstraction that is gained by passing the
whole entity justify doing it this way?

If I need to add an order for a Customer. I could do it the following two
ways:

1) public static int InsertOrder(Cus tomer customer, Order order)
-or-
2) public static int InsertOrder(int customerID, Order order)

WHICH IS BETTER?

Thank you in advance!
-AV
Nov 15 '05 #1
11 3169

"Arsen Vladimirskiy" <ar***@emergenc y24.com> wrote in message
news:On******** *****@TK2MSFTNG P11.phx.gbl...
Hello,

If I have a few simple classes to represent Entities such as Customers and
Orders.

What is the proper way to pass information to the Data Access Layer?

1) Pass the actual ENTITY to the Data Access Layer method
-or-
2) Pass some kind of a unique id to the Data Access Layer method

For example, how should the DAL.FindCustome r method be implemented:

1) public static Customer FindCustomer(Cu stomer customer);
-or-
If you already have the Customer object, what would FindCustomer do?
.. . . I understand that passing the ENTITY is more expensive than passing a single unique key.
Nope. No more or less expensive. You are just passing a reference to the
entity.
However, does the abstraction that is gained by passing the .. . .
1) public static int InsertOrder(Cus tomer customer, Order order)


Definity this one. You should pass your entity objects except where you are
loading them from the database, of course.

David
Nov 15 '05 #2
Hi David,

The public static Customer FindCustomer(Cu stoemr customer) is used to look
for the FULL customer Entity using a partially filled-in entity that is
passed to it.

So for example, I could pass the customer.Custom erID and FindCustomer would
return the FULL Customer entity with all the fields filled in.

In a sense, the FindCustomer is the one that loads the customer from the
database into an ENTITY object. Should I make it FindCustomerByI D(int
customerID) instead?

Thanks,
AV

"David Browne" <davidbaxterbro wne no potted me**@hotmail.co m> wrote in
message news:%2******** ********@TK2MSF TNGP12.phx.gbl. ..

"Arsen Vladimirskiy" <ar***@emergenc y24.com> wrote in message
news:On******** *****@TK2MSFTNG P11.phx.gbl...
Hello,

If I have a few simple classes to represent Entities such as Customers and Orders.

What is the proper way to pass information to the Data Access Layer?

1) Pass the actual ENTITY to the Data Access Layer method
-or-
2) Pass some kind of a unique id to the Data Access Layer method

For example, how should the DAL.FindCustome r method be implemented:

1) public static Customer FindCustomer(Cu stomer customer);
-or-
If you already have the Customer object, what would FindCustomer do?

. . .
I understand that passing the ENTITY is more expensive than passing a

single
unique key.


Nope. No more or less expensive. You are just passing a reference to the
entity.
However, does the abstraction that is gained by passing the

. . .

1) public static int InsertOrder(Cus tomer customer, Order order)


Definity this one. You should pass your entity objects except where you

are loading them from the database, of course.

David

Nov 15 '05 #3

"Arsen Vladimirskiy" <ar***@emergenc y24.com> wrote in message
news:u6******** ******@TK2MSFTN GP10.phx.gbl...
Hi David,

The public static Customer FindCustomer(Cu stoemr customer) is used to look
for the FULL customer Entity using a partially filled-in entity that is
passed to it.

So for example, I could pass the customer.Custom erID and FindCustomer would return the FULL Customer entity with all the fields filled in.

In a sense, the FindCustomer is the one that loads the customer from the
database into an ENTITY object. Should I make it FindCustomerByI D(int
customerID) instead?


Yes. I think partially loaded entity objects are a needless complication.

David
Nov 15 '05 #4
Hi Arsen,

It depend of the way you ( or your team) design the system and the system
requeriments tiself.

I will give you an example of how I designed the system I'm working right
now.
I have classes that represent the entities of my business, each of these
classes export a number of properties, and a method Save() , inside this
method I create a SqlCommand with the SP and its parameters , then I call
the DAL class that simply execute the command,
The good think I see in develop like this is that the logic to "save" an
entity is inside that entity. relying in an external object to really
execute the command in the database.

This would not work if for example the backend could be one of several DB
engines. As in my particular case the backend is SQL Server I can safely
pass a SqlCommand.
Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Arsen Vladimirskiy" <ar***@emergenc y24.com> wrote in message
news:On******** *****@TK2MSFTNG P11.phx.gbl...
Hello,

If I have a few simple classes to represent Entities such as Customers and
Orders.

What is the proper way to pass information to the Data Access Layer?

1) Pass the actual ENTITY to the Data Access Layer method
-or-
2) Pass some kind of a unique id to the Data Access Layer method

For example, how should the DAL.FindCustome r method be implemented:

1) public static Customer FindCustomer(Cu stomer customer);
-or-
2) public static Customer FindCustomer(in t customerID);

If I need to find a customer either by an ID or by the username, what is the proper way:

1) public static Customer FindCustomer(Cu stomer customer); // and the method will look at the filled-in properties of Customer and determine what to
search by
-or-
2) public static Customer FindCustomerByI D(int customerID); and public
static Customer FindCustomerByU sername(string username);

I understand that passing the ENTITY is more expensive than passing a single unique key. However, does the abstraction that is gained by passing the
whole entity justify doing it this way?

If I need to add an order for a Customer. I could do it the following two
ways:

1) public static int InsertOrder(Cus tomer customer, Order order)
-or-
2) public static int InsertOrder(int customerID, Order order)

WHICH IS BETTER?

Thank you in advance!
-AV

Nov 15 '05 #5
Actually, you could have your design work if you passed a IDbCommand object
instead. I do something similiar to what you do and my data helper classes
take the IDBCommand which will allow different backends. Just a FYI.

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us > wrote
in message news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
Hi Arsen,

It depend of the way you ( or your team) design the system and the system requeriments tiself.

I will give you an example of how I designed the system I'm working right
now.
I have classes that represent the entities of my business, each of these
classes export a number of properties, and a method Save() , inside this
method I create a SqlCommand with the SP and its parameters , then I call
the DAL class that simply execute the command,
The good think I see in develop like this is that the logic to "save" an
entity is inside that entity. relying in an external object to really
execute the command in the database.

This would not work if for example the backend could be one of several DB
engines. As in my particular case the backend is SQL Server I can safely
pass a SqlCommand.
Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Arsen Vladimirskiy" <ar***@emergenc y24.com> wrote in message
news:On******** *****@TK2MSFTNG P11.phx.gbl...
Hello,

If I have a few simple classes to represent Entities such as Customers and Orders.

What is the proper way to pass information to the Data Access Layer?

1) Pass the actual ENTITY to the Data Access Layer method
-or-
2) Pass some kind of a unique id to the Data Access Layer method

For example, how should the DAL.FindCustome r method be implemented:

1) public static Customer FindCustomer(Cu stomer customer);
-or-
2) public static Customer FindCustomer(in t customerID);

If I need to find a customer either by an ID or by the username, what is

the
proper way:

1) public static Customer FindCustomer(Cu stomer customer); // and the

method
will look at the filled-in properties of Customer and determine what to
search by
-or-
2) public static Customer FindCustomerByI D(int customerID); and public
static Customer FindCustomerByU sername(string username);

I understand that passing the ENTITY is more expensive than passing a

single
unique key. However, does the abstraction that is gained by passing the
whole entity justify doing it this way?

If I need to add an order for a Customer. I could do it the following two ways:

1) public static int InsertOrder(Cus tomer customer, Order order)
-or-
2) public static int InsertOrder(int customerID, Order order)

WHICH IS BETTER?

Thank you in advance!
-AV


Nov 15 '05 #6
Hi Darin,

No really, as the Command is buid inside the entity it would need to know
what kind of backend it's in use to build the correct one.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Darin" <none> wrote in message
news:OB******** ******@TK2MSFTN GP11.phx.gbl...
Actually, you could have your design work if you passed a IDbCommand object instead. I do something similiar to what you do and my data helper classes take the IDBCommand which will allow different backends. Just a FYI.

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us > wrote in message news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
Hi Arsen,

It depend of the way you ( or your team) design the system and the

system
requeriments tiself.

I will give you an example of how I designed the system I'm working right
now.
I have classes that represent the entities of my business, each of these
classes export a number of properties, and a method Save() , inside this
method I create a SqlCommand with the SP and its parameters , then I call the DAL class that simply execute the command,
The good think I see in develop like this is that the logic to "save" an entity is inside that entity. relying in an external object to really
execute the command in the database.

This would not work if for example the backend could be one of several DB engines. As in my particular case the backend is SQL Server I can safely
pass a SqlCommand.
Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Arsen Vladimirskiy" <ar***@emergenc y24.com> wrote in message
news:On******** *****@TK2MSFTNG P11.phx.gbl...
Hello,

If I have a few simple classes to represent Entities such as Customers and Orders.

What is the proper way to pass information to the Data Access Layer?

1) Pass the actual ENTITY to the Data Access Layer method
-or-
2) Pass some kind of a unique id to the Data Access Layer method

For example, how should the DAL.FindCustome r method be implemented:

1) public static Customer FindCustomer(Cu stomer customer);
-or-
2) public static Customer FindCustomer(in t customerID);

If I need to find a customer either by an ID or by the username, what is the
proper way:

1) public static Customer FindCustomer(Cu stomer customer); // and the

method
will look at the filled-in properties of Customer and determine what
to search by
-or-
2) public static Customer FindCustomerByI D(int customerID); and public
static Customer FindCustomerByU sername(string username);

I understand that passing the ENTITY is more expensive than passing a

single
unique key. However, does the abstraction that is gained by passing the whole entity justify doing it this way?

If I need to add an order for a Customer. I could do it the following

two ways:

1) public static int InsertOrder(Cus tomer customer, Order order)
-or-
2) public static int InsertOrder(int customerID, Order order)

WHICH IS BETTER?

Thank you in advance!
-AV



Nov 15 '05 #7
Ignacio,

I disagree with you. My object objects do not care which back end is
being used: it could be SQL Server, Access, Oracle, an XML file, or some
other type of data store that I do choose to support in my object
framework. My business and dataobjects manipulate only IDataParameters ,
IDbCommands, IDbConnections, and so on. The use of polymorphism in this
context is highly recommended, especially since .NET is already doing
all the hard work for you. ;-)

Gilles

Ignacio Machin ( .NET/ C# MVP ) wrote:
Hi Darin,

No really, as the Command is buid inside the entity it would need to know
what kind of backend it's in use to build the correct one.

Cheers,


Nov 15 '05 #8
While this is MOSTLY true, you will find that some providers/drivers don't
support certain features, don't use certain features with the same results,
or perform poorly with certain generic operations. The devil's in the
details :-)
While I agree that polymorphism is outstanding for dealing with
database-agnostic code, I recommend doing something a little more
high-level, and making the data layer itself more specific. For example,
plug-in interfaces for data access modules, which then internally do
whatever optimized job they have to talk to specific databases. It might
seem a bit more complicated at the outset, but it's better than hitting some
unkown database driver bug/limitation and realizing you have to write
specific workaround code anyway, only this way, the structure is more
formalized.

But that's just my opinion. Feel free to disagree, as Dennis Miller would
say :-)

-Rob Teixeira [MVP]

"Gilles Muys" <gm***@gmsoftwa re.com> wrote in message
news:ut******** ******@TK2MSFTN GP09.phx.gbl...
Ignacio,

I disagree with you. My object objects do not care which back end is
being used: it could be SQL Server, Access, Oracle, an XML file, or some
other type of data store that I do choose to support in my object
framework. My business and dataobjects manipulate only IDataParameters ,
IDbCommands, IDbConnections, and so on. The use of polymorphism in this
context is highly recommended, especially since .NET is already doing
all the hard work for you. ;-)

Gilles

Ignacio Machin ( .NET/ C# MVP ) wrote:
Hi Darin,

No really, as the Command is buid inside the entity it would need to know what kind of backend it's in use to build the correct one.

Cheers,

Nov 15 '05 #9
Tim
Ignacio Machin,

Is it your view, that custom classes are the best design to represent
business entities? I am wrestling with the idea of either using custom
classes or typed datasets. Also, do u pass your business entities around or
do you make their properties static? For instance, in might need a business
entity of data (user input/db values) for a business object that does some
calculations and then you might need that same business entity for a report.

Thanks

"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us > wrote
in message news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
Hi Arsen,

It depend of the way you ( or your team) design the system and the system requeriments tiself.

I will give you an example of how I designed the system I'm working right
now.
I have classes that represent the entities of my business, each of these
classes export a number of properties, and a method Save() , inside this
method I create a SqlCommand with the SP and its parameters , then I call
the DAL class that simply execute the command,
The good think I see in develop like this is that the logic to "save" an
entity is inside that entity. relying in an external object to really
execute the command in the database.

This would not work if for example the backend could be one of several DB
engines. As in my particular case the backend is SQL Server I can safely
pass a SqlCommand.
Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Arsen Vladimirskiy" <ar***@emergenc y24.com> wrote in message
news:On******** *****@TK2MSFTNG P11.phx.gbl...
Hello,

If I have a few simple classes to represent Entities such as Customers and Orders.

What is the proper way to pass information to the Data Access Layer?

1) Pass the actual ENTITY to the Data Access Layer method
-or-
2) Pass some kind of a unique id to the Data Access Layer method

For example, how should the DAL.FindCustome r method be implemented:

1) public static Customer FindCustomer(Cu stomer customer);
-or-
2) public static Customer FindCustomer(in t customerID);

If I need to find a customer either by an ID or by the username, what is

the
proper way:

1) public static Customer FindCustomer(Cu stomer customer); // and the

method
will look at the filled-in properties of Customer and determine what to
search by
-or-
2) public static Customer FindCustomerByI D(int customerID); and public
static Customer FindCustomerByU sername(string username);

I understand that passing the ENTITY is more expensive than passing a

single
unique key. However, does the abstraction that is gained by passing the
whole entity justify doing it this way?

If I need to add an order for a Customer. I could do it the following two ways:

1) public static int InsertOrder(Cus tomer customer, Order order)
-or-
2) public static int InsertOrder(int customerID, Order order)

WHICH IS BETTER?

Thank you in advance!
-AV


Nov 15 '05 #10

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

Similar topics

3
4744
by: Simon Harvey | last post by:
Hi, In my application I get lots of different sorts of information from databases. As such, a lot of information is stored in DataSets and DataTable objects. Up until now, I have been passing around chunks of data in DataTables/DataSets, simply because that was the format that they were in when the data was taken from the database. Now,...
7
2353
by: Jack Addington | last post by:
I've got a fairly simple application implementation that over time is going to get a lot bigger. I'm really trying to implement it in a way that will facilitate the growth. I am first writing a WinForms interface and then need to port that to a web app. I am kinda stuck on a design issue and need some suggestions / direction. Basically I...
9
6252
by: Hasan O. Zavalsiz | last post by:
Hi , i am trying to figure out which approach is better to use . let me explain the scenario. i am using the "Nortwind" database . in this database i have "Customers " table .The following is the two different ways to handle this table. CASE 1 : create a struct that encaplusates table "Customers" columns public struct structCustomers {...
11
2539
by: Peter M. | last post by:
Hi all, I'm currently designing an n-tier application and have some doubts about my design. I have created a Data Access layer which connects to the database (SQL Server) and performs Select, update, delete and inserts. I use dataset objects to pass data to and from the DAL. In my GUI (windows forms), I use databinding to bind controls...
19
2507
by: Chocawok | last post by:
Some of the classes in my app are graphical. To encapsulate the graphical side of things I had created a class called "sprite" which holds a bit map and knows how to draw itself etc. The classes that are graphical contain a sprite object.
17
2582
by: Divick | last post by:
Hi, I am designing an API and the problem that I have is more of a design issue. In my API say I have a class A and B, as shown below class A{ public: void doSomethingWithB( B * b) { //do something with b //possibly store in a list
18
1970
by: _dee | last post by:
Question about best use of interfaces: Say there's a 'Master' class that needs to implement a few interfaces: class Master : I1, I2, I3 { } The actual code already exists in smaller classes that each
0
1987
by: AMDRIT | last post by:
I am looking for better concrete examples, as I am a bit dense, on design patterns that facilitate my goals. I have been out to the code project, planet source code, and microsoft's patterns and practices site and it just isn't sinking in all that clearly to me. Currently we have code in production and it all works well, however it is...
2
2629
by: grawsha2000 | last post by:
Greetings, I am developing this N-tier business app. The problem I'm facing is when I try to pass business objects (employees, dept..etc) from business tier to data tier,i.e., the add method in the data tier expects business object from the business tier, I get an error saying: Can not covert businesslayer.emp to businesslayer.emp
0
7843
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...
0
7764
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...
0
8111
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8274
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7863
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...
0
3776
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...
1
2282
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
1
1375
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1102
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...

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.