Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / April 2008

Tip: Looking for answers? Try searching our database.

HowTo? LINQ Query Table Name (Range Variable) Not Known Until Runtime

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Joey - 23 Apr 2008 15:37 GMT
I am querying a DataSet with LINQ. I am running into a problem when
trying to construct my query because in the "from" clause I do not
know the table name (range variable) until runtime. Possible table
names might include "SomeTable1" or "SomeTable236" etc...
Unfortunately when I try to use something like "from SomeTable +
MyChangingNumber.ToString() in..." in my from clause it does not work.
How can I set this up to use a range variable whose value is dynamic /
not known until runtime?
Patrice - 23 Apr 2008 16:04 GMT
You could try the dynamic LINQ library (but I never used it and I'm not sure
it covers this scenario) :
http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-
linq-dynamic-query-library.aspx


Which programming language are you using ? You could likely use Reflection
in C# or CallByName in VB.NET (I tried this later method once) to
dynamically call the appropriate member on the DataContext.

I understand you may have some reasons for this design but I'm not a big fan
of those "select by table name instead of using a where clause" design and
it could be likely a subject of its own...

Finally you'll find a LINQ specific forum at :
http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=123&SiteID=1

--
Patrice

"Joey" <joey.powell@topscene.com> a écrit dans le message de groupe de
discussion :
220288e6-a8c6-4964-afd7-339db08922b2@k37g2000hsf.googlegroups.com...
> I am querying a DataSet with LINQ. I am running into a problem when
> trying to construct my query because in the "from" clause I do not
[quoted text clipped - 4 lines]
> How can I set this up to use a range variable whose value is dynamic /
> not known until runtime?
bruce barker - 23 Apr 2008 17:33 GMT
Linq does not support this. the lambda expression that represents the table
name is converted to an expression tree at compile time (so no variables
allowed). you can write you own method to create the expression tree at
runtime, and then construct the linq query.

-- bruce (sqlwork.com)

> I am querying a DataSet with LINQ. I am running into a problem when
> trying to construct my query because in the "from" clause I do not
[quoted text clipped - 4 lines]
> How can I set this up to use a range variable whose value is dynamic /
> not known until runtime?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.