ToTable overload to support multiple database joins on the same sql server

Topics: EF Runtime
Dec 13, 2012 at 11:56 AM

For Linq2Sql and EF database first I have been able to modify the schema.table to include a database name, in Linq2Sql I managed to make it definable at runtime so that is what I'm using for multiple database joins at the moment.

I want to move over to code first but I cannot find any way to add the database to the generated SQL. I have tried several combinations with ToTable() like ToTable("table", "database.dbo") and so on. But I either get invalid table/databasename or I get extra/misplaced square brackets in the query. Tried this both in EF 5 and 6a2 but neither works for me with the hack above. I would like something like this:

public void ToTable(string tableName, string schemaName, string databaseName);

I could then pass in the second database into the mappings constructor and define it at runtime to support joins between databases on the same sql server.

Any other suggestions how to hack this with EF4-5 would be appreciated as well, needs to be runtime definable.

Perhaps once EF6 is out of alpha and beta I'll look into it myself to build a custom variant but I would prefer a out of the box solution.

Dec 19, 2012 at 6:01 PM

Hi NetQvist,

Thanks for starting this discussion. I have created an issue for this which we will investigate and see if anything can be done for EF6 or later: