2016-12-30 23 views
0

我有一個表單,需要從我用LLBLGen DataAccessAdapter訪問的數據庫填充下拉(文本和值)。
我正在使用Telerik,如果這提供了任何其他有用的信息或選項。通用實體/集合使用LLBLGen DataAccessAdapter獲取?

有沒有辦法做到這一點一般,這樣我可以簡單地調用類似:

DropDown.DataSource = GetEntityCollection<OrderEntity>(); 

DropDown.DataSource = GetEntityCollection(OrderEntity); 

我最初試圖做到這一點像下面看到的,但沒有版本我遇到的這個想法似乎解釋了我的整個情景。因爲我需要將類型作爲泛型或參數傳入,所以我不能使用EntityCollection<>需要的類型(即EntityBase2)。

public static object GetEntityCollection<T>() //Or 
{ 
    using (DataAccessAdapter adapter = new DataAccessAdapter(CONNECTION)) 
    { 
     EntityCollection<typeof(T)> collection = new EntityCollection<typeof(T)>(); 
     try 
     { 
      adapter.FetchEntityCollection(collection, null); 
     } 
     catch 
     { 

     } 

     return collection; 
    } 
} 

如果直接是不可能的,有沒有更好的方式來拆分此,以避免改寫爲多,因爲我需要獲取每一個數據庫實體?

回答

1
public static IEntityCollection2 GetEntityCollection<T>() where T : EntityBase2 
{ 
    using (DataAccessAdapter adapter = new DataAccessAdapter()) 
    { 
     IEntityCollection2 collection = new EntityCollection<T>(); 
     try 
     { 
      adapter.FetchEntityCollection(collection, null); 
     } 
     catch 
     { 
      //Log Exception 
     } 

     return collection; 
    } 
}