导读:
在.NET 3.5 平台上使用LINQ to SQL创建三层/多层Web应用系统 (Part 4)
构建业务外观层(Business Facade Layer)
所有业务逻辑将在这一层实现。一般而言,这一层负责处理数据和在表现层与数据访问层之间传递数据。这一层从物理上提供上层接口隔离表现层代码和数据访问层代码,ASP.NET页面不能直接与数据访问层交互。相反,页面应该调用业务外观层的方法。图3.1 展示了业务外观层的详细视图。
图3.1:业务外观层-详细视图
在我们的示例程序中,业务外观层仅仅包含一个组件-BFLCustomer。示例代码如下:
代码片段1.2 :业务外观层
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
usingDataAccess;
usingSystem.Data.Linq;
usingDataLinq;
namespaceBusinessFacade
{
publicclassBFLCustomer
{
privateDALCustomerobjDataAccess = newDALCustomer();
publicTable SelectRecordAll()
{
returnobjDataAccess.SelectRecordAll();
}
publicCustomerSelectRecordByID(stringcustomerID)
{
returnobjDataAccess.SelectRecordByID(customerID);
}
publicList SelectRecordByIDListable(stringcustomerID)
{
returnobjDataAccess.SelectRecordByIDListable(customerID);
}
publicstringInsertRecord(CustomerlocalTable)
{
returnobjDataAccess.InsertRecord(localTable);
}
publicvoidUpdateRecord(CustomerlocalTable)
{
objDataAccess.UpdateRecord(localTable);
}
publicvoidDeleteRecord(stringcustomerID)
{
objDataAccess.DeleteRecord(customerID);
}
publicTable SelectAllOrder()
{
returnobjDataAccess.SelectAllOrder();
}
publicTable SelectAllOrderDetail()
{
returnobjDataAccess.SelectAllOrderDetail();
}
}
}
BFLCustomer 组件包括下面类图所示的公共方法列表,这些方法用来与数据访问层交换。
注:业务外观层没有创建DataContext类的实例,因此它不能够实现任何数据访问逻辑。
BFLCustomer 组件的类图如下:
图3.2:业务外观层 – 类图
EntLib.com开源小组注:本文翻译《Building Multi-Tier Web Application in .NET 3.5 Framework Using LINQ to SQL》。后面内容待续。欢迎交流LINQ相关技术。
上几篇文章:
在.NET 3.5 平台上使用LINQ to SQL创建三层/多层Web应用系统 (Part 4)
构建业务外观层(Business Facade Layer)
所有业务逻辑将在这一层实现。一般而言,这一层负责处理数据和在表现层与数据访问层之间传递数据。这一层从物理上提供上层接口隔离表现层代码和数据访问层代码,ASP.NET页面不能直接与数据访问层交互。相反,页面应该调用业务外观层的方法。图3.1 展示了业务外观层的详细视图。
图3.1:业务外观层-详细视图
在我们的示例程序中,业务外观层仅仅包含一个组件-BFLCustomer。示例代码如下:
代码片段1.2 :业务外观层
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
usingDataAccess;
usingSystem.Data.Linq;
usingDataLinq;
namespaceBusinessFacade
{
publicclassBFLCustomer
{
privateDALCustomerobjDataAccess = newDALCustomer();
publicTable SelectRecordAll()
{
returnobjDataAccess.SelectRecordAll();
}
publicCustomerSelectRecordByID(stringcustomerID)
{
returnobjDataAccess.SelectRecordByID(customerID);
}
publicList SelectRecordByIDListable(stringcustomerID)
{
returnobjDataAccess.SelectRecordByIDListable(customerID);
}
publicstringInsertRecord(CustomerlocalTable)
{
returnobjDataAccess.InsertRecord(localTable);
}
publicvoidUpdateRecord(CustomerlocalTable)
{
objDataAccess.UpdateRecord(localTable);
}
publicvoidDeleteRecord(stringcustomerID)
{
objDataAccess.DeleteRecord(customerID);
}
publicTable SelectAllOrder()
{
returnobjDataAccess.SelectAllOrder();
}
publicTable SelectAllOrderDetail()
{
returnobjDataAccess.SelectAllOrderDetail();
}
}
}
BFLCustomer 组件包括下面类图所示的公共方法列表,这些方法用来与数据访问层交换。
注:业务外观层没有创建DataContext类的实例,因此它不能够实现任何数据访问逻辑。
BFLCustomer 组件的类图如下:
图3.2:业务外观层 – 类图
EntLib.com开源小组注:本文翻译《Building Multi-Tier Web Application in .NET 3.5 Framework Using LINQ to SQL》。后面内容待续。欢迎交流LINQ相关技术。
上几篇文章: