【发布时间】:2019-05-15 22:27:03
【问题描述】:
我的解决方案中有 3 层:
- DAL(正在使用 LINQ 访问我的数据库)
- 业务层
- Winform
在我的 DAL 中,我从我的数据库中返回一个具有特定类型的 List,并且我在我的 BLL 中做同样的事情。
当我想在我的 UI 中使用我的函数时,我得到了错误:
“Reservation”类型是在未引用的程序集中定义的...
现在我想避免在我的 UI 中引用我的 DAL。
由于我是新手,无法在网上找到明确的答案,请谁能帮帮我?
我的 DAL 函数
public static List<Reservation> SelectListReservation()
{
try
{
List<Reservation> lstReservation = new List<Reservation>();
lstReservation = oExamenSgbdEntities.Reservations.ToList();
return lstReservation;
}
catch (Exception e)
{
throw e;
}
}
我的 BLL 函数
public static List<DataAccess.Reservation> GetListReservation()
{
try
{
List<DataAccess.Reservation> lstToReturn = new List<Reservation>();
lstToReturn = GetListReservation();
return lstToReturn;
}
catch (Exception e)
{
throw e;
}
}
如何在 UI 中调用 BL 函数:
var lstRes = Manage.GetListReservation();
【问题讨论】:
-
无意义的
try…catch…throw块有什么用? -
他不知道你可以告诉调试器在第一个异常时中断。
-
顺便说一句,如果你这样做,你应该只做一个
throw;而不是throw e; -
@MatthewWhited 是正确的,
throw ewill reset the stack trace。 -
那我不应该使用 throw e 吗?还是我应该只在特定层中使用它?我只想在最后的 MessageBox 中显示错误。
标签: c# linq architecture data-access-layer business-logic-layer