title: Can code-first Entity Framework do cross database queries with SQL Server DBs on the same box?
body: <p>I know there have been a lot of questions about Entity Framework doing cross database queries on the same server posted to <a href="https://stackoverflow.com/questions/610197/ado-net-entity-framework-across-multiple-databases">stackoverflow</a>. Mostly the answer seems to be 'no', and this link from <a href="http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/cad06147-2168-4c20-ac23-98f32987b126/" rel="nofollow noreferrer">way back in 2008 is referenced</a>.  However, Entity Framework is changing all the time and with CTP5 out, I'm wondering if the answer is still the same - that you can't do it, or you can do it if you manually edit the edmx file, or you have to use views.  This feature alone is the reason I'm still tied to Linq-to-SQL, as we have multiple SQL Server 2008 databases on the same server and need to query across them.  Polluting our databases with hundreds of <code>select *</code> views is not an option, and with code-first development I don't have an edmx file to edit.  I was playing with the pubs database to see if I could get somewhere, but I'm stuck.  Any suggestions?</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Diagnostics;
  using System.Linq;
  using System.ComponentModel.DataAnnotations;
  using System.Data.Entity;
  using System.Data.Entity.ModelConfiguration;
  
  namespace DbSchema {
      public class Employee {
          [Key]
          public string ID { get; set; }
          public string FirstName { get; set; }
          public string LastName { get; set; }
          public short JobID { get; set; }
          public Job Job { get; set; }
      }
  
      public class Job {
          [Key]
          public short ID { get; set; }
          public string Description { get; set; }
      }
  
      public class PubsRepository : DbContext {
          public DbSet&lt;Employee&gt; Employee { get; set; }
          public DbSet&lt;Job&gt; Job { get; set; }
  
          protected override void OnModelCreating(ModelBuilder modelBuilder) {
              // employee
              var eeMap = modelBuilder.Entity&lt;Employee&gt;();
              eeMap.ToTable("employee", "dbo"); // &lt;-- how do I reference another database?
              eeMap.Property(e =&gt; e.ID).HasColumnName("emp_id");
              eeMap.Property(e =&gt; e.FirstName).HasColumnName("fname");
              eeMap.Property(e =&gt; e.LastName).HasColumnName("lname");
              eeMap.Property(e =&gt; e.JobID).HasColumnName("job_id");
  
              // job
              var jobMap = modelBuilder.Entity&lt;Job&gt;();
              jobMap.Property(j =&gt; j.ID).HasColumnName("job_id");
              jobMap.Property(j =&gt; j.Description).HasColumnName("job_desc");
          }
  
          public List&lt;Employee&gt; GetManagers() {
              var qry = this.Employee.Where(x =&gt; x.Job.Description.Contains("manager"));
              Debug.WriteLine(qry.ToString());
              return qry.ToList(); // &lt;-- error here when referencing another database!
          }
      }
  }
  </code></pre>