关于传递实体对象的设计问题 [英] Design Question About Passing Entity Objects

查看:66
本文介绍了关于传递实体对象的设计问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


如果我有几个简单的类来代表客户和

订单等实体。


将信息传递到数据访问层的正确方法是什么?


1)将实际的ENTITY传递给数据访问层方法

- 或者 -

2)将某种唯一ID传递给数据访问层方法


例如,如何实现DAL.FindCustomer方法:


1)public static Customer FindCustomer(客户客户);

-or-

2)public static Customer FindCustomer(int customerID);


如果我需要通过ID或用户名找到客户,那么

的正确方法是什么:


1)public static Customer FindCustomer(客户客户); //和方法

将查看Customer的填充属性并确定

搜索的内容

-or-

2)public static Customer FindCustomerByID(int customerID);和公众

静态客户FindCustomerByUsername(字符串用户名);


我明白通过ENTITY比传递一个
$ b $更贵b唯一的钥匙。但是,通过传递

整个实体获得的抽象是否可以这样做呢?


如果我需要为客户添加订单。我可以用以下两种方式来做

方式:


1)public static int InsertOrder(客户客户,订单)

- 或 -

2)public static int InsertOrder(int customerID,Order order)


哪个更好?


提前谢谢你!

-AV

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

推荐答案



" Arsen Vladimirskiy" ; < AR *** @ emergency24.com>在消息中写道

新闻:关于************* @ TK2MSFTNGP11.phx.gbl ...

"Arsen Vladimirskiy" <ar***@emergency24.com> wrote in message
news:On*************@TK2MSFTNGP11.phx.gbl...
你好,

如果我有一些简单的类来表示客户和
订单等实体。

将信息传递到数据访问层的正确方法是什么?

1)将实际的ENTITY传递给数据访问层方法
- 或 -
2)将一些唯一的ID传递给数据访问层方法

例如,如何实现DAL.FindCustomer方法:

1)public static Customer FindCustomer(客户客户);
- 或 -


如果您已经拥有Customer对象,那么FindCustomer会做什么?


.. 。我知道传递ENTITY比传递
单一唯一键更昂贵。


不。没有更多或更便宜。你只是传递一个对

实体的引用。

然而,通过传递
获得的抽象。 。
1)public static int InsertOrder(客户客户,订单)
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-
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(Customer customer, Order order)




定义这一个。你应该传递你的实体对象,除非你在那里

从数据库加载它们。


David



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

David


嗨David,


公共静态客户FindCustomer(Custoemr客户)用于查看使用部分填充的FULL客户实体的
-in
传递给它的实体。


例如,我可以传递customer.CustomerID和FindCustomer将

返回填写了所有字段的FULL Customer实体。


从某种意义上说,FindCustomer是将客户从

数据库加载到一个ENTITY对象。我应该改为FindCustomerByID(int

customerID)吗?


谢谢,

AV


" David Browne" < davidbaxterbrowne没有盆栽 me**@hotmail.com >写在

消息新闻:%2 **************** @ TK2MSFTNGP12.phx.gbl ...
Hi David,

The public static Customer FindCustomer(Custoemr 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.CustomerID 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 FindCustomerByID(int
customerID) instead?

Thanks,
AV

"David Browne" <davidbaxterbrowne no potted me**@hotmail.com> wrote in
message news:%2****************@TK2MSFTNGP12.phx.gbl...

Arsen Vladimirskiy < AR *** @ emergency24.com>在消息中写道
新闻:在************* @ TK2MSFTNGP11.phx.gbl ...

"Arsen Vladimirskiy" <ar***@emergency24.com> wrote in message
news:On*************@TK2MSFTNGP11.phx.gbl...
你好,

如果我有一些简单的类来表示实体,例如Customers
和Orders。

将信息传递到数据访问层的正确方法是什么?

1)将实际的ENTITY传递给数据访问层方法
- 或 -
2)将某种唯一的ID传递给数据访问层方法

例如,如何应该实现DAL.FindCustomer方法:1)public static Customer FindCustomer(客户客户);
- 或 -
如果您已经拥有Customer对象,那么FindCustomer会是什么做什么?
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-
If you already have the Customer object, what would FindCustomer do?


。 。 。


. . .

我知道传递ENTITY比传递
I understand that passing the ENTITY is more expensive than passing a


单个

唯一键更贵。


<不,不。没有更多或更便宜。您只是传递对
实体的引用。



Nope. No more or less expensive. You are just passing a reference to the
entity.

但是,通过传递


获得的抽象。 。 。


. . .


1)public static int InsertOrder(客户客户,订单)

1) public static int InsertOrder(Customer customer, Order order)



确定这个。你应该传递你的实体对象,除非你



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



正在从数据库加载它们。

David


are loading them from the database, of course.

David





" Arsen Vladimirskiy" < AR *** @ emergency24.com>在消息中写道

news:u6 ************** @ TK2MSFTNGP10.phx.gbl ...

"Arsen Vladimirskiy" <ar***@emergency24.com> wrote in message
news:u6**************@TK2MSFTNGP10.phx.gbl...
嗨大卫,

公共静态客户FindCustomer(Custoemr客户)用于查看完整客户实体使用部分填写的实体(
传递给它)。
<例如,我可以传递customer.CustomerID和FindCustomer
将返回填写了所有字段的FULL Customer实体。

从某种意义上说,FindCustomer就是一个将客户从
数据库加载到ENTITY对象中。我应该改为FindCustomerByID(int
customerID)吗?
Hi David,

The public static Customer FindCustomer(Custoemr 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.CustomerID 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 FindCustomerByID(int
customerID) instead?




是的。我认为部分加载的实体对象是一种不必要的复杂问题。


David



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

David


这篇关于关于传递实体对象的设计问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆