Binding Linq Query to Entity Class
<p>I am  using a simple LINQ query <code>SingleOrDefault</code> in the applicaiton to get  a record and bind it back to entity class. I am getting a exception which says specific cast is not valid.</p>

<p>I ran the SQL Profiler to see  if the query yields successfull result and I was able to row back from database.</p>

<p>Unfortunately the exisitng table has more than 120 columns and I am not able to figure where the casting is getting failed.</p>

<p>Taking a glance on the data would not say me much about where the specific cast is invalid.</p>

<p>Please let me know how to solve this problem or identity exactly which column has invalid cast.</p>

<pre><code>PatientDetail objPatientDetails_Toupdate = null;
        objSummitHealthDataContext = new SummitHealthDataContext();
        try
        {
            objPatientDetails_Toupdate = objSummitHealthDataContext.PatientDetails.SingleOrDefault(pd =&gt; pd.PatientID == objPatientDetails.PatientID);
            if (objPatientDetails_Toupdate == null)
            {
</code></pre>

<p>Exception From Stack Trace:</p>

<blockquote>
  <p>at System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query,
  QueryInfo queryInfo, IObjectReaderFactory factory, Object[]
  parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object
  lastResult)    at
  System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query,
  QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[]
  userArguments, ICompiledSubQuery[] subQueries)    at
  System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression
  query)    at
  System.Data.Linq.Table<code>1.System.Linq.IQueryProvider.Execute[TResult](Expression
  expression)    at
  System.Linq.Queryable.FirstOrDefault[TSource](IQueryable</code>1 source,
  Expression`1 predicate)    at
  SummitHealth.CRM.Data.Patient.PatientDAO.SavePatient(PatientDetail
  objPatientDetails)</p>
</blockquote>