3

看完这篇 ,我还有一个问题:

我使用此代码查询数据库:

c# :

new BLL().GetPersonById(1)

BLL :

public Person GetPersonById(int id)
{
  return new DAL ().GetPersonById(1);
}

DAL :

public Person  GetPersonById(int id)
{
   // goto db and create instance of Person and fill its data...
}

但是,我做错了吗,

我的 DAL 应该返回DataTable ?(所以 BLL 将创建 Person ....?)

DAL :

public DataTable  GetPersonById(int id)
{
   // goto db ...
}

谢谢你。

编辑 :

Person 对象在BE dll(业务实体)中定义。

4

2 回答 2

3

"Should my DAL return DataTable instead ? ( so the BLL will create Person .... ?)"

Not at all. Ideally DAL is supposed to deal with database and should return entity/application objects to BAL. DAL works as a abstraction for database to BLL.

And I am agree with MikeSW as he said "BLL shouldn't depend on the DAL, at most it defines some interfaces which will be implemented in the DAL."

于 2012-11-07T08:36:56.877 回答
1

您的 DAL,确切地说是存储库,返回 Person,它是 BLL 中定义的业务对象。

BLL 不应该依赖于 DAL,最多它定义了一些将在 DAL 中实现的接口。但是,该应用程序向 DAL 请求存储的业务对象,因为它负责处理所有持久性。

And yes, the DAL depends on the BLL. THe DAL sohld return only aplication objects (business objects or view models), everything persistence access related should be hidden.

于 2012-11-07T08:06:31.743 回答