title: How to check if data exist in SQL table using EF code first in ASP.NET MVC application?
body: <p>I have this model class:</p>
  
  <pre><code>public class MembershipSerial
  {
      [HiddenInput(DisplayValue=false)]
      public int Id { get; set; }
      [HiddenInput(DisplayValue=false)]
      public string Serial { get; set; }
      [Required]
      [Display(Name="Membership Serial")]
      public string SerialConfirmed { get; set; }
  }
  </code></pre>
  
  <p>I am using EF code-first approach, I would like to check the value of the Serial vs SerialConfirmed and find any Serial which is equal to SerialConfirmed. </p>
  
  <p>I tried below but i get a null exception and don't know how to solve this?</p>
  
  <pre><code>    public ActionResult Checkout(UserDetails Details)
      {
          if (Details.MembershipSerial.Serial.Any().ToString() == Details.MembershipSerial.SerialConfirmed)
          {
              return View("UserSerial");
          }
  
          return View();
      }
  
      public class UserDetails : IdentityUser
      {
          public virtual DeliveryDetails DeliveryDetails { get; set; }
          public virtual UserOrders UserOrders { get; set; }
          public virtual MembershipSerial MembershipSerial { get; set; }
      }
  </code></pre>
  
  <p><strong>Edit:</strong></p>
  
  <pre><code>public class MembershipSerial
  {
      [HiddenInput(DisplayValue=false)]
      public int Id { get; set; }
      [HiddenInput(DisplayValue=false)]
      public string Serial { get; set; }
      [Required]
      [Display(Name="Membership Serial")]
      public string SerialConfirmed { get; set; }
  }
  
  public class DeliveryDetails
  {
      public int Id { get; set; }
      public string FirstName { get; set; }
      public string LastName { get; set; }
      public string Phone { get; set; }
      public string Company { get; set; }
      public string Address { get; set; }
      public string AddressLine2 { get; set; }
      public string District { get; set; }
      public string Province { get; set; }
  }
  public class UserOrders
  {
      public int Id { get; set; }
      public string ProductName { get; set; }
  }
  
  public class MyDbContext : IdentityDbContext&lt;UserDetails&gt;
  {
      public MyDbContext()
          : base ("EFDbContext")
      {
      }
      public System.Data.Entity.DbSet&lt;MembershipSerial&gt; MembershipSerial { get; set; }
      public System.Data.Entity.DbSet&lt;DeliveryDetails&gt; DeliveryDetails { get; set; }
      public System.Data.Entity.DbSet&lt;UserOrders&gt; UserOrders { get; set; }
  }
  </code></pre>
  
  <p>Any help is appreciated. Thanks in advance.</p>