title: EF5 Code First (Error cannot be inferred from the usage)
body: <p>Ok, I have been pulling out my hair because I simply cannot make a many to many relationship. I have the following two models:</p>
  
  <pre><code>public class UserProfile
  {
      [Key]
      [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
      public int UserId { get; set; }
      public string UserName { get; set; }
      public string CompanyName { get; set; }
      public string FirstName { get; set; }
      public string Lastname { get; set; }
      public string EmailAddress { get; set; }
      public string PhoneNumber { get; set; }
      public bool? ChangePassword { get; set; }
      public bool? Deletable { get; set; }
  
      //Add more Properties for more fields
  
      public virtual IQueryable&lt;CompanyInformation&gt; ParentCompany { get; set; }
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>public class CompanyInformation
  {
      [Key]
      [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
      public int id { get; set; }
  
      [DisplayName("Company Name:")]
      public string companyName { get; set; }
  
      [DisplayName("Website Address:")]
      [Url(ErrorMessage="The Website field is not a valid fully-qualified http, https, or ftp URL. (Example: http://www.website.com)")]
      public string website { get; set; }
      public string contactTitle { get; set; }
  
      [DisplayName("Contact First Name:")]
      public string contactFirstName { get; set; }
      //[Required]
      [DisplayName("Contact Last Name:")]
      public string contactLastName { get; set; }
  
      [Phone]
      [DisplayName("Phone Number:")]
      public string contactPhoneNumber { get; set; }
  
      [DisplayName("Address Display?")]
      public bool displayAddress { get; set; }
      [DisplayName("Phone Number?")]
      public bool displayPhoneNumber { get; set; }
  
      [DisplayName("Address 1:")]
      public string address1 { get; set; } 
      [DisplayName("Address 2:")]
      public string address2 { get; set; }
  
      [DisplayName("City:")]
      public string city { get; set; }
  
      [DisplayName("State:")]
      public string state { get; set; }
  
      [DisplayName("Zip/Postal Code:")]
      public string zipCode { get; set; }
  
      [DisplayName("Search Engine?")]
      public bool allowSearchEngines { get; set; }
  
  
      //Navigation Property
      public virtual IQueryable&lt;UserProfile&gt; CompanyUsers{ get; set; }
  
  }
  </code></pre>
  
  <p>I'm trying to make a many-to-many relationship between these two and I just can't figure out how to do it properly. I should mention that I am very new to the EF Code First.
  My Context Class looks like the following:</p>
  
  <pre><code>public class myDB : DbContext
  {
      public SchedulerDB()
          : base("DefaultConnection")
      {
  
      }
  
      public DbSet&lt;UserProfile&gt; UserProfiles { get; set; }
      public DbSet&lt;CompanyInformation&gt; Companies { get; set; }
  
      protected override void OnModelCreating(DbModelBuilder modelBuilder)
      {
          modelBuilder.Entity&lt;UserProfile&gt;().HasMany(e =&gt; e.ParentCompanies).WithMany(e =&gt; e.CompanyUsers);            
      }
  
  }
  </code></pre>
  
  <p>ok, As soon as I add the modelBuilder above I get the following error:</p>
  
  <pre><code>The type arguments for method 'System.Data.Entity.ModelConfiguration.EntityTypeConfiguration&lt;Scheduler.Model.UserProfile&gt;.HasMany&lt;TTargetEntity&gt;(System.Linq.Expressions.Expression&lt;System.Func&lt;Scheduler.Model.UserProfile,System.Collections.Generic.ICollection&lt;TTargetEntity&gt;&gt;&gt;)' cannot be inferred from the usage. Try specifying the type arguments explicitly.  C:\Users\Hiva\Documents\Project\ToDo\Infrastructure\myDB.cs
  </code></pre>
  
  <p>What am I doing wrong? I can't seem to find any examples that use the modelBuilder differently to achieve a many-to-many relationship between two tables. Thank you in advanced for your help.</p>