2016-12-30 25 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; 
    } 
}