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();
Sign up to request clarification or add additional context in comments.

1 Comment

Is there a way to make this work With Self tracking Entities (who do not inherit from EntityObject) ?
1

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

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.