實戰 .Net 資料訪問層 - 13
來源:互聯網
上載者:User
訪問|資料 具體的Data Access Logic實現技術,作者感覺已沒有必要多加討
論,相信只要是有過ADO.NET開發經驗的同志都比較清楚應該怎
麼做,網上的資料也浩如煙海,非常齊全!
在此,就以作者自己的一段Data Access Logic代碼來結束關於它的討論:
代碼11:使用Data Access Logic進行Remoting調用 – 1,基本操作
class CustomerDal_ORM : MyDal
{
protected internal MyCustomer GetAllCustomers()
{
MyCustomer cust = null;
// 擷取Distributed Process類型
string typeDist = GetDistributionType();
switch (typeDist)
{
case DistributionType.REMOTING :
{
// 通過Cache Management訪問資料,第2參數是個delegate,
// 一旦Cache失效,就直接通過該delegate重新整理資料
ArrayList al = CacheManager.Current.GetCache(
GetCacheParam(), GetAllCustomers_Remoting_delegate);
... // 對Remoting返回的資料進行處理
break;
}
default :
throw new Exception(
"Unsupported DistributionType: " +
typeDist + "!");
}
return cust;
}
}
}
上面的是基本存取碼,由於使用了Cache Management,所以
我們還需要一段真正可以訪問資料的代碼,一旦Cache失效,就可
以通過它來再次獲得資料並重新整理緩衝!
需要特別注意的是:上面的代碼使用了C# 2.0中的Anonymous
Delegate功能,如果在Visual Studio .NET 2003種進行編譯,必須將
GetAllCustomers_Remoting_delegate參數修改為如下方式:
new GetArrayList(GetAllCustomers_Remoting_delegate)
(這裡的GetArrayList就是真正定義的delegate類型)
下一段:http://www.csdn.net/develop/Read_Article.asp?id=27557