7

Closed

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.
Closed Dec 12, 2016 at 9:25 PM by RoMiller
EF Team Triage: We are transitioning this project to GitHub (https://github.com/aspnet/EntityFramework6). As part of this transition we are bulk closing a large number of issues in order that our new issue tracker will accurately reflect the work that our team is planning to complete on the EF6.x code base.

Moving forwards, our team will be fixing bugs, implementing small improvements, and accepting community contributions to the EF6.x code base. Larger feature work and innovation will happen in the EF Core code base (https://github.com/aspnet/EntityFramework). Closing a feature request in the EF6.x project does not exclude us implementing the feature in EF Core. In fact, a number of popular feature requests for EF have already been implemented in EF Core (alternate keys, batching in SaveChanges, etc.).

This is a bulk message to indicate that this issue was closed and not ported to the new issue tracker. The reasons for not porting this particular issue to GitHub may include:
  • It was a bug report that does not contain sufficient information for us to be able to reproduce it
  • It was a question, but sufficient time has passed that it's not clear that taking the time to answer it would provide value to the person who asked it
  • It is a feature request that we are realistically not going to implement on the EF6.x code base
    Although this issue was not ported, you may still re-open it in the new issue tracker for our team to reconsider (https://github.com/aspnet/EntityFramework6/issues). We will no longer be monitoring this issue tracker for comments, so please do not reply here.

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.