views:

48

answers:

2

I have a Entity model that includes a large number of lookup entities. All have just ID and Name properties.

I do not want to build large number of DAL classes to simply have something like:

IList<Lookup1> lookup1List= ctx.Lookup1.ToList();

and another class (Or method) with

IList<Lookup2> lookup2List= ctx.Lookup2.ToList();

and another with

IList<Lookup3> lookup3List= ctx.Lookup3.ToList();

I want to have one generic way to query all them using an interface they all Implement. Something like

IList<ILookupEntity> list = "SomeMethod"(Type lookupType);

How can I do that?

+5  A: 

What about this?

public class Repository<T> where T : EntityObject, new()
{
    public static IQueryable<T> List()
    {
        return EntityContext.Current.CreateObjectSet<T>();
    }
}

Usage:

var lookups = Repository<Lookup1>.List();
Rubens Farias
Is there a way to make this work With Self tracking Entities (who do not inherit from EntityObject) ?
Emad
A: 

So you want to query all objects that implement a specific interface? I don't think that's possible, currently.

Zor