6
Vote

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

description

Copied from discussion thread: http://entityframework.codeplex.com/discussions/406642

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.

comments

glennc wrote Dec 19, 2012 at 10:05 PM

Assigned to EF6.

We will take this to the design meeting.

luggage66 wrote Feb 5, 2013 at 4:37 PM

This surprised me. I'll be using Views to get around it for now but wish I didn't have to.

edsoncunha wrote Apr 18, 2013 at 2:44 PM

I'm willing to adopt EF Code First for many projects, but all the related databases are legacy and cannot be changed. This limitation prevents me from using EF.

robyferro wrote May 30, 2013 at 1:04 PM

Same problem as edsoncunha, legacy databases on same server that cannot be changed.