title: Unable to cast object of type JoinIterator
body: <p>I am getting this error: </p>
  
  <blockquote>
    <p>Unable to cast object of type
    'd__37'4[System.Xml.Linq.XElement,BankOfBIT.Models.BankAccount,System.Int64,&lt;>f__AnonymousType2'1[System.Xml.Linq.XElement]]'
    to type
    'System.Collections.Generic.IEnumerable`1[System.Xml.Linq.XElement]'.</p>
  </blockquote>
  
  <p>I am trying to execute this lambda query:</p>
  
  <pre><code>IEnumerable&lt;XElement&gt; transactionsWithMatchingAccountNumber
  = (IEnumerable&lt;XElement&gt;) transactionswithValidAmount.Join(
      db.BankAccounts,
      transactions =&gt; long.Parse(transactions.Element("account_no").Value),
      accounts =&gt; accounts.AccountNumber,
      (transactions, accounts) =&gt; new { XElement = transactions });
  </code></pre>
  
  <p>I am trying to only get all xml transactions that match with account number in the database to verify they exist.</p>
  
  <p>I have an <code>IEnumerable&lt;XElement&gt;</code> that contains these:</p>
  
  <pre><code>&lt;transaction&gt;
      &lt;institution&gt;34439&lt;/institution&gt;
      &lt;account_no&gt;10000&lt;/account_no&gt;
      &lt;type&gt;2&lt;/type&gt;
      &lt;amount&gt;50&lt;/amount&gt;
      &lt;notes&gt;withdrawal&lt;/notes&gt;
  &lt;/transaction&gt;
  </code></pre>
  
  <p>I have 2 EntityFramework MVC Classes with these Schemas:</p>
  
  <pre><code>public class Transaction
  {   
     [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
     public int TransactionId { get; set; }
  
     public long TransactionNumber { get; set; }
  
     [ForeignKey("BankAccount")]
     [Required]
     public int BankAccountId { get; set; }
  
     [ForeignKey("TransactionType")]
     [Required]
     public int TransactionTypeId { get; set; }
  
     public double Deposit { get; set; }
  
     public double Withdrawal { get; set; }
  
     [Required]
     public DateTime DateCreated { get; set; }
  
     public string Notes { get; set; }
     /// &lt;summary&gt;
     /// create account with default next num
     /// &lt;/summary&gt;
     public void SetNextTransactionNumber()
     {
         this.TransactionNumber = (long) StoredProcedures.NextNumber("NextTransactionNumbers");
     }
  
     public virtual BankAccount BankAccount { get; set; }
  
     public virtual TransactionType TransactionType { get; set; }
  }
  
  public abstract class BankAccount
  {
      [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
      public int BankAccountId { get; set; }
  
      [Display(Name="Account\nNumber")]
      public long AccountNumber { get; set; }
  
      [Required]
      [ForeignKey("Client")]
      public int ClientId { get; set; }
  
      [Required]
      [ForeignKey("AccountState")]
      public int AccountStateId { get; set; }
  
      [Required]
      [Display(Name = "Current\nBalance")]
      [DisplayFormat(DataFormatString="{0:c2}")]
      public double Balance { get; set; }
  
      [Required]
      [Display(Name = "Opening\nBalance")]
      [DisplayFormat(DataFormatString = "{0:c2}")]
      public double OpeningBalance { get; set; }
  
      [Required]
      [Display(Name = "Date\nCreated")]
      [DisplayFormat(DataFormatString = "{0:d}")]
      public DateTime DateCreated { get; set; }
  
  
      [Display(Name = "Account\nNotes")]
      public string Notes { get; set; }
  
      /// &lt;summary&gt;
      /// Returns the name of the account type
      /// &lt;/summary&gt;
      [Display(Name = "Account\nType")]
      public string Description
      {
          get
          {
              return GetType().Name.Split('_')[0].Replace("Account","");
          }
      }
  
      /// &lt;summary&gt;
      /// Stores the bank account state
      /// &lt;/summary&gt;
      public virtual AccountState AccountState { get; set; }
  
      /// &lt;summary&gt;
      /// Stores the client associated with the bank account
      /// &lt;/summary&gt;
      public virtual Client Client { get; set; }
  
      /// &lt;summary&gt;
      /// Increments the account number static counter
      /// &lt;/summary&gt;
      public abstract void SetNextAccountNumber();
  
      /// &lt;summary&gt;
      /// Changes the state of the bank account
      /// &lt;/summary&gt;
      public void ChangeState()
      {
          BankOfBITContext db = new BankOfBITContext();
  
          AccountState lastState;
          AccountState futureState;
  
          do{
  
              lastState = db.AccountStates.Find(AccountStateId);
  
              lastState.StateChangeCheck(this);
  
              futureState = db.AccountStates.Find(AccountStateId);
  
          }while(lastState != futureState);
      }
  }
  </code></pre>