1

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?

2 Answers 2

5

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();
1
  • Is there a way to make this work With Self tracking Entities (who do not inherit from EntityObject) ? Sep 10, 2010 at 15:52
1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.