gixx
gixx

Reputation: 1

Dynamic table names with Linq to entities?

I wondered if there is a way to provide a table name for linq query at runtime. I am interested in simple query like

select * from @someTableName

I've searched a lot for the answer but couldn't find any help on the net. There was a post on MSDN --> link

Dave Russel suggested to do:

var p = ctx.GetType.GetProperty(oName).getValue(ctx,null) 

But apart from getting property with reflection I don't know how to work out the rest in order to be able to execute queries against that property like:

from x in p select x; 

Upvotes: 0

Views: 1022

Answers (1)

Devart
Devart

Reputation: 121902

Try the ExecuteStoreQuery method. You execute a SQL query and obtain ObjectResult. Please note that this method is available only in Entity Framework v4.

Upvotes: 1

Related Questions