title: Linq help using "Contains"
body: <p>Good Morning All,</p>
  
  <p>I'm trying to use "Contains" to see if an object is within the collection. When I break I can see that the object is indeed part of the collection however "Contains" seems to be returning false indicating the item is not in the collection. Any idea what I'm doing wrong?</p>
  
  <pre><code>if(HttpContext.Current.Session["AutoPayTypes"] != null)
  {
      var autopays = HttpContext.Current.Session["AutoPayTypes"] as List&lt;PaymentTypeInfo&gt;;
      char? coverageProductLine = null;
  
      if(entityProps.ContainsKey("CoverageProductLine"))
      {
         coverageProductLine = (char?)entityProps["CoverageProductLine"];
      }
  
      var paymentTypeInfoRepository = new PaymentTypeInfoRepository();
      var payType = paymentTypeInfoRepository.GetPaymentTypeInfo(paymentAdd.PayType,
      coverageProductLine);
  
      if (autopays != null &amp;&amp; payType != null)
          paymentAdd.DaysPaid = autopays.Contains(payType) ? null : paymentAdd.DaysPaid;
  }
  </code></pre>
  
  <p>If the object is not in the collection the "DaysPaid" needs to be null. Any ideas?</p>
  
  <p>***UPDATE
  PaymentTypeInfo is a standard LinqToSql generated class. Equals nor GetHashCode has been overridden at this point. Here is it's source.</p>
  
  <pre><code>[Table(Name="dbo.S_OptPaymentType")]
  public partial class PaymentTypeInfo
  {
  
      private string _PaymentId;
  
      private string _PaymentCode;
  
      private System.Nullable&lt;char&gt; _CoverageType;
  
      private string _ActionCode;
  
      private System.Nullable&lt;char&gt; _PaymentType;
  
      private string _BenAction;
  
      private System.Nullable&lt;char&gt; _BenPremDisFlag;
  
      private string _APNextToLastAct;
  
      private string _APLastAct;
  
      public PaymentTypeInfo()
      {
      }
  
      [Column(Storage="_PaymentId", DbType="Char(3) NOT NULL", CanBeNull=false)]
      public string PaymentId
      {
          get
          {
              return this._PaymentId;
          }
          set
          {
              if ((this._PaymentId != value))
              {
                  this._PaymentId = value;
              }
          }
      }
  
      [Column(Storage="_PaymentCode", DbType="Char(2) NOT NULL", CanBeNull=false)]
      public string PaymentCode
      {
          get
          {
              return this._PaymentCode;
          }
          set
          {
              if ((this._PaymentCode != value))
              {
                  this._PaymentCode = value;
              }
          }
      }
  
      [Column(Storage="_CoverageType", DbType="Char(1)")]
      public System.Nullable&lt;char&gt; CoverageType
      {
          get
          {
              return this._CoverageType;
          }
          set
          {
              if ((this._CoverageType != value))
              {
                  this._CoverageType = value;
              }
          }
      }
  
      [Column(Storage="_ActionCode", DbType="VarChar(3)")]
      public string ActionCode
      {
          get
          {
              return this._ActionCode;
          }
          set
          {
              if ((this._ActionCode != value))
              {
                  this._ActionCode = value;
              }
          }
      }
  
      [Column(Name="PaymentType", Storage="_PaymentType", DbType="Char(1)")]
      public System.Nullable&lt;char&gt; PaymentType
      {
          get
          {
              return this._PaymentType;
          }
          set
          {
              if ((this._PaymentType != value))
              {
                  this._PaymentType = value;
              }
          }
      }
  
      [Column(Storage="_BenAction", DbType="VarChar(3)")]
      public string BenAction
      {
          get
          {
              return this._BenAction;
          }
          set
          {
              if ((this._BenAction != value))
              {
                  this._BenAction = value;
              }
          }
      }
  
      [Column(Storage="_BenPremDisFlag", DbType="Char(1)")]
      public System.Nullable&lt;char&gt; BenPremDisFlag
      {
          get
          {
              return this._BenPremDisFlag;
          }
          set
          {
              if ((this._BenPremDisFlag != value))
              {
                  this._BenPremDisFlag = value;
              }
          }
      }
  
      [Column(Storage="_APNextToLastAct", DbType="VarChar(3)")]
      public string APNextToLastAct
      {
          get
          {
              return this._APNextToLastAct;
          }
          set
          {
              if ((this._APNextToLastAct != value))
              {
                  this._APNextToLastAct = value;
              }
          }
      }
  
      [Column(Storage="_APLastAct", DbType="VarChar(3)")]
      public string APLastAct
      {
          get
          {
              return this._APLastAct;
          }
          set
          {
              if ((this._APLastAct != value))
              {
                  this._APLastAct = value;
              }
          }
      }
  }
  </code></pre>
  
  <p>Thanks,
  ~ck in San Diego</p>