Jan Hommes
Jan Hommes

Reputation: 5152

How to get table dynamic in EntityFramework 5

I'm switching form LINQ to SQL to EntityFramework 5. In LINQ to SQL I have used this function, to get a table just by its type (VB-Code):

Dim type As Type = myObject.GetType()
Dim context As MyEntities = New MyEntities()
query = context.GetTable(type).AsQueryable()

Now I'm searching for an equal method in EF5. I have found this answer on SO, but my context doesn't has a method called CreateObjectSet. Is this because of difference between EF4 and EF5, or am I missing something?

Upvotes: 1

Views: 1234

Answers (1)

Jan Hommes
Jan Hommes

Reputation: 5152

Based on this answer I found out that I can use Set instead of CreateObjectSet:

Public Function GetTable(Of T As Class)(entity As T) As IQueryable
    Return dbContext.Set(Of T)()
End Function

Upvotes: 1

Related Questions