title: Entity Framework RC1 DbContext query issue
body: <p>I'm trying to implement the repository pattern using entity framework code first rc 1.  The problem I am running into is with creating the DbContext.  I have an ioc container resolving the IRepository and it has a contextprovider which just news up a new DbContext with a connection string in a windsor.config file. With linq2sql this part was no problem but EF seems to be choking.  I'll describe the problem below with an example.  I've pulled out the code to simplify things a bit so that is why you don't see any repository pattern stuff here. just sorta what is happening without all the extra code and classes.</p>
  
  <pre><code>            using (var context = new PlssContext())
              {
                  var x = context.Set&lt;User&gt;();
                  var y = x.Where(u =&gt; u.UserName == LogOnModel.UserName).FirstOrDefault();
              }
  
              using (var context2 = new DbContext(@"Data Source=.\SQLEXPRESS;Initial Catalog=PLSS.Models.PlssContext;Integrated Security=True;MultipleActiveResultSets=True"))
              {
                  var x = context2.Set&lt;User&gt;();
                  var y = x.Where(u =&gt; u.UserName == LogOnModel.UserName).FirstOrDefault();
              }
  </code></pre>
  
  <p>PlssContext is where I am creating my DbContext class.  The repository pattern doesn't know anything about PlssContext. The best I thought I could do was create a DbContext with the connection string to the sqlexpress database and query the data that way. The connection string in the var context2 was grabbed from the context after newing up the PlssContext object.  So they are pointing at the same sqlexpress database.</p>
  
  <p>The first query works.  The second query fails miserably with this error:</p>
  
  <blockquote>
    <p>The model backing the 'DbContext'
    context has changed since the database
    was created. Either manually
    delete/update the database, or call
    Database.SetInitializer with an
    IDatabaseInitializer instance. For
    example, the
    DropCreateDatabaseIfModelChanges
    strategy will automatically delete and
    recreate the database, and optionally
    seed it with new data.</p>
  </blockquote>
  
  <p>on this line</p>
  
  <pre><code>var y = x.Where(u =&gt; u.UserName == LogOnModel.UserName).FirstOrDefault();
  </code></pre>
  
  <p>Here is my DbContext</p>
  
  <pre><code>namespace PLSS.Models
  {
      public class PlssContext : DbContext
      {
          public DbSet&lt;User&gt; Users { get; set; }
          public DbSet&lt;Corner&gt; Corners { get; set; }
          public DbSet&lt;Lookup_County&gt; Lookup_County { get; set; }
          public DbSet&lt;Lookup_Accuracy&gt; Lookup_Accuracy { get; set; }
          public DbSet&lt;Lookup_MonumentStatus&gt; Lookup_MonumentStatus { get; set; }
          public DbSet&lt;Lookup_CoordinateSystem&gt; Lookup_CoordinateSystem { get; set; }
  
          public class Initializer : DropCreateDatabaseAlways&lt;PlssContext&gt;
          {
              protected override void Seed(PlssContext context)
              {
  </code></pre>
  
  <p>I've tried all of the Initializer strategies with the same errors. I don't think the database is changing. If I remove the </p>
  
  <pre><code>     modelBuilder.Conventions.Remove&lt;IncludeMetadataConvention&gt;();
  </code></pre>
  
  <p>Then the error returns is </p>
  
  <blockquote>
    <p>The entity type User is not part of the model for the current context.</p>
  </blockquote>
  
  <p>Which sort of makes sense. But how do you bring this all together?</p>