title: WebSecurity.CreateUserAndAccount propertyValues
body: <p>I'm writing an mvc 4 c# .net 4.5 website</p>
  
  <p>I want to create a new company object and register a new user that is linked to that company.</p>
  
  <p>My account model is:</p>
  
  <pre><code>    [Table("UserProfile")]
      public class UserProfile
      {
          [Key]
          [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
          public int UserId { get; set; }
          public string UserName { get; set; }
          public string FirstName { get; set; }
          public string LastName { get; set; }
          public string EmailAddress { get; set; }
          public string PhoneNumber { get; set; }
          public bool MarketingEmailOptin { get; set; }
          public bool isDisabled { get; set; }
          public virtual Company CompanyICanEdit { get; set; } 
      }
  </code></pre>
  
  <p>If i call the following it adds the user fine but has null for the CompanyICanEdit field:</p>
  
  <pre><code>WebSecurity.CreateUserAndAccount(addCompanyViewModel.User.UserName,
                                   addCompanyViewModel.User.Password,
                                   propertyValues: new
                                   {
                                     FirstName = addCompanyViewModel.User.FirstName,
                                     LastName = addCompanyViewModel.User.LastName,
                                     EmailAddress = addCompanyViewModel.User.EmailAddress,
                                     PhoneNumber = addCompanyViewModel.User.PhoneNumber,
                                     MarketingEmailOptin = addCompanyViewModel.User.MarketingEmailOptin,
                                     isDisabled = false
                                   });
  </code></pre>
  
  <p>which i would expect as i am not assigning it anything.</p>
  
  <p>i have tried adding (mycompany is a company object):</p>
  
  <pre><code>    WebSecurity.CreateUserAndAccount(addCompanyViewModel.User.UserName,
                                   addCompanyViewModel.User.Password,
                                   propertyValues: new
                                   {
                                     FirstName = addCompanyViewModel.User.FirstName,
                                     LastName = addCompanyViewModel.User.LastName,
                                     EmailAddress = addCompanyViewModel.User.EmailAddress,
                                     PhoneNumber = addCompanyViewModel.User.PhoneNumber,
                                     MarketingEmailOptin = addCompanyViewModel.User.MarketingEmailOptin,
                                     isDisabled = false,
                                     CompanyICanEdit = mycompany
                                   });
  </code></pre>
  
  <p>But i get an error saying it can't match the type.</p>
  
  <p>How do i go about registering the user so that the CompanyICanEdit contains the CompanyId value of mycompany?</p>
  
  <p>Any help will be appreciated. thanks</p>