Does the ADO.NET Entity Framework have a construct similar to LINQ to SQL GetTable <T>?

Does ADO.NET Entity Framework have a construct similar to LINQ to SQL GetTable?

I am trying to do something similar in Entity Framework, which I am very used to doing in LINQ to SQL . ADO.NET Entity Framework has the same capability?

LINQ to SQL:

dataContext.GetTable<T>();

      

This will result in a Queryable of type "T".

In Entity Framework, I would like to do the same:

    //NOTICE: This is a partial extension of the auto-generated Entities-model
    //        created by the designer.
    public partial class Entities : IEntities
    {
      public IQueryable<T> FindAll<T>()
      {
        //pseudo-code
        // return from all entities, the entities that are of type T as Queryable
      }
    }

      

Since I couldn't figure it out, I did what I find to be a "smelly" workaround:

    //NOTICE: This is a partial extension of the auto-generated Entities-model
    //        created by the designer.
    public partial class Entities : IEntities
    {
      public IQueryable<Users> FindAllUsersQueryable
      {
        get { return Users; }
      }

      public IQueryable<Registrations> FindAllRegistrationsQueryable
      {
        get { return Registrations; }
      }

      //... and so on ...
    }

      

What I want is similar to:

    //NOTICE: This is a partial extension of the auto-generated Entities-model
    //        created by the designer.
    public partial class Entities : IEntities
    {
      public IQueryable<T> FindAll<T>()
      {
        return GetEntities<T>();
      }
    }

      

But so far I haven't been able to find out how to do it.

What solution?

+2


source to share


2 answers


    public IQueryable<T> FindAll<T>()
    {
        var baseType = typeof(T);
        return CreateQuery<T>("[" + baseType.Name.ToString() + "]").OfType<T>();
    }

      



And it seems to do the job for me :-)

0


source


Marking like a wiki as I can't claim credit, but MSFT's answer to this question is here: What is the equivilant of GetTable in L2E .



+2


source







All Articles