A
Arsen Vladimirskiy
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.FindCustomer method be implemented:
1) public static Customer FindCustomer(Customer customer);
-or-
2) public static Customer FindCustomer(int 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(Customer customer); // and the method
will look at the filled-in properties of Customer and determine what to
search by
-or-
2) public static Customer FindCustomerByID(int customerID); and public
static Customer FindCustomerByUsername(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(Customer customer, Order order)
-or-
2) public static int InsertOrder(int customerID, Order order)
WHICH IS BETTER?
Thank you in advance!
-AV
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.FindCustomer method be implemented:
1) public static Customer FindCustomer(Customer customer);
-or-
2) public static Customer FindCustomer(int 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(Customer customer); // and the method
will look at the filled-in properties of Customer and determine what to
search by
-or-
2) public static Customer FindCustomerByID(int customerID); and public
static Customer FindCustomerByUsername(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(Customer customer, Order order)
-or-
2) public static int InsertOrder(int customerID, Order order)
WHICH IS BETTER?
Thank you in advance!
-AV