tags:

views:

82

answers:

3

I have a database called MasterDatabase that has table MainIndex with columns Id, Database (nvarchar), Table(nvarchar)

and I have 2 other databases with tables and data.

Is there a way to substitute the FROM statement with results from the MasterDatabase.MainIndex?

Can this be done with LINQ?

A: 

You need the Linq Dynamic Query library to accomplish this. It allows you to do string substitutions in your Linq queries.

More info at http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx

Robert Harvey
A: 

Or you can access tables from another database by prefixing the tables in your .dbml with either [DatabaseName].[SchemaName].[TableName] or if it's on a differenct server include the [ServerName] as well... Then you wouldn't have to use Dynamic linq

J.13.L
Im not sure what you mean by "prefixing the tables"thanks
in the LinqToSql dbml manually add the table that is from the database outside of the one used in your connection string. Right click on that table and select properties... There is a property called Source which is the name of the table in the database... Then rename the table with the above instructions...
J.13.L
+1  A: 

Another alternative is to add the table you want to select from from the second database as a view in the master database. You will then be able to map the view as an entity.

:)

Chalkey