看完this ,我还有一个问题:
我使用这段代码来查询数据库:
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(业务实体)中定义。
最佳答案
"Should my DAL return DataTable instead ? ( so the BLL will create Person .... ?)"
完全没有。理想情况下,DAL 应该处理数据库并且应该将实体/应用程序对象返回给 BAL。 DAL 作为 BLL 的数据库抽象。
我同意 MikeSW 的说法,他说“BLL 不应该依赖于 DAL,它最多定义一些将在 DAL 中实现的接口(interface)。”
关于c# - 我的 DAL 应该返回 Person 还是 Datatable?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13265445/