Generic Entity/Collection Fetching with LLBLGen DataAccessAdapter?

482 views Asked by At

I have a form, which needs to have drop downs (Text and Value) populated from a database I'm accessing with LLBLGen DataAccessAdapter.
I'm using Telerik, if this provides any additional useful information or options.

Is there a way to do this generically so that I can simply call something like:

DropDown.DataSource = GetEntityCollection<OrderEntity>();

or

DropDown.DataSource = GetEntityCollection(OrderEntity);

I was initially attempting to do this like seen below, but no version of this idea I've come across seems to account for my whole scenario. Since I need the type to be passed in as a generic or parameter I can't use as the type that EntityCollection<> needs (which is 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;
    }
}

If this is not possible directly, is there a better way to split this up to avoid rewriting as a much for every single database entity I need to fetch?

1

There are 1 answers

1
Nol On BEST ANSWER
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;
    }
}