title: MVC5 VB.Net - Single dbContext and Migrations
body: <p>This is somewhat to do with best practice, but also some practical questions.</p>
  
  <p>I'm new to MVC, and .Net in general, having been a PHP developer previously. I'm loving it on the whole, and Entity Framework / Code First is a bit special.</p>
  
  <p>So I've done a bit of work on my first project, and my first issue is that there doesn't seem to be a lot of documentation for VB - I can't use C# because the other developers here are all VB guys. I can get around that on the whole but does anyone know of a good resource, book or online, for MVC5 &amp; VB?</p>
  
  <p>Now for my problem. My project is going to contain a lot of data. I've no problem with creating the models and using migrations to get the tables up and running, and I can query them with complex joins, get my views to work, dynamic forms and whatnot.</p>
  
  <p>Currently I have two data connections, one for the Identity stuff, and one for everything else (as in the examples on the MVC site).</p>
  
  <p>This week the brief has changed and I now need to include more user data, and link my users to other tables in my other connection.</p>
  
  <p>For example, I need to add a clientCompany table, with a corresponding field in my Users Table. A given clientCompany will have salesRegions, which each have postCodes, etc. etc.</p>
  
  <p>So to join my Identity User table to my others, and set up foreign keys, would they need to occupy the same connection, and dbContext?</p>
  
  <p>I seem to be able to have migrations set up for just one of my dbContexts at a time, so that makes me think I need to have everything in one dbContext. I've seen discussions about Inheriting the IdentityDbContext in my own dbContext class, but I can't get it to work - only the Identity tables, and tables linked to them by FKs are creating / updating.</p>
  
  <p>Here's my IdentityModels.vb</p>
  
  <pre><code>Public Class ApplicationUser
      Inherits IdentityUser
      Property emailAddress() As String
      Overridable Property clientCompany() As ClientCompany
  End Class
  
  Public Class ApplicationDbContext
      Inherits IdentityDbContext(Of ApplicationUser)
  
      Public Class IdentityDbContext
          Public Property IdentityDbContext() As ApplicationDbContext
      End Class
      Public Sub New()
          MyBase.New("ExportEntities")
      End Sub
  End Class
  </code></pre>
  
  <p>And here's my own dbContext class, ExportEntities.vb</p>
  
  <pre><code>Namespace models
  
  Public Class ExportEntities
  
      'Inherits DbContext
      Inherits IdentityDbContext
  
      'Metadata Heirarchy
      Public Property Products() As DbSet(Of Product)
      Public Property ProductVersions() As DbSet(Of ProductVersion)
      Public Property dbSplits() As DbSet(Of dbSplit)
      Public Property Sections() As DbSet(Of Section)
      Public Property FieldGroups() As DbSet(Of FieldGroup) 'Not all fields are organised into groups
      Public Property FieldNames() As DbSet(Of FieldName)
  
  etc...
  </code></pre>
  
  <p>And finally my connection string:</p>
  
  <pre><code>&lt;connectionStrings&gt;
  
      &lt;add name="ExportEntities" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=&amp;quot;|DataDirectory|\Export.mdf&amp;quot;;Initial Catalog=&amp;quot;Export&amp;quot;;Integrated Security=True"
    providerName="System.Data.SqlClient" /&gt;
  &lt;/connectionStrings&gt;
  </code></pre>
  
  <p>Can anyone point me in the right direction please?</p>
  
  <p>Thanks in advance</p>
  
  <p>Simon</p>