简体   繁体   中英

Generic Entity/Collection Fetching with LLBLGen DataAccessAdapter?

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?

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;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM