title: System.String ElementAt[String](System.Collections.Generic.IEnumerable`1[System.String], Int32)' method
body: <p>I am recieving the exception mentioned in quotes below. I have tried to remove the problem alot but i am getting the exception below. I have read similiar answers to my problem in stack over flow but they don't solve my problem. I have also commented above the line where i recieve exception.</p>
  
  <blockquote>
    <p>System.NotSupportedException was unhandled by user code<br>
    HResult=-2146233067   Message=LINQ to Entities does not recognize the
    method 'System.String
    ElementAt[String](System.Collections.Generic.IEnumerable<code>1[System.String],
    Int32)' method, and this method cannot be translated into a store
    expression.   Source=EntityFramework   StackTrace:
           at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.DefaultTranslator.Translate(ExpressionConverter
    parent, MethodCallExpression call)
           at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter
    parent, MethodCallExpression linq)
           at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator</code>1.Translate(ExpressionConverter
    parent, Expression linq)
           at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression
    linq)
           at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.UnaryTranslator.TypedTranslate(ExpressionConverter
    parent, UnaryExpression linq)
           at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator<code>1.Translate(ExpressionConverter
    parent, Expression linq)
           at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression
    linq)
           at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.EqualsTranslator.TypedTranslate(ExpressionConverter
    parent, BinaryExpression linq)
           at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator</code>1.Translate(ExpressionConverter
    parent, Expression linq)
           at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression
    linq)
           at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression
    lambda, DbExpression input)
           at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateLambda(LambdaExpression
    lambda, DbExpression input, DbExpressionBinding&amp; binding)
           at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.OneLambdaTranslator.Translate(ExpressionConverter
    parent, MethodCallExpression call, DbExpression&amp; source,
    DbExpressionBinding&amp; sourceBinding, DbExpression&amp; lambda)
           at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.OneLambdaTranslator.Translate(ExpressionConverter
    parent, MethodCallExpression call)
           at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SequenceMethodTranslator.Translate(ExpressionConverter
    parent, MethodCallExpression call, SequenceMethod sequenceMethod)
           at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter
    parent, MethodCallExpression linq)
           at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator<code>1.Translate(ExpressionConverter
    parent, Expression linq)
           at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression
    linq)
           at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.OneLambdaTranslator.Translate(ExpressionConverter
    parent, MethodCallExpression call, DbExpression&amp; source,
    DbExpressionBinding&amp; sourceBinding, DbExpression&amp; lambda)
           at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SelectTranslator.Translate(ExpressionConverter
    parent, MethodCallExpression call)
           at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SequenceMethodTranslator.Translate(ExpressionConverter
    parent, MethodCallExpression call, SequenceMethod sequenceMethod)
           at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter
    parent, MethodCallExpression linq)
           at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator</code>1.Translate(ExpressionConverter
    parent, Expression linq)
           at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression
    linq)
           at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateSet(Expression
    linq)
           at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.UnarySequenceMethodTranslator.Translate(ExpressionConverter
    parent, MethodCallExpression call)
           at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SequenceMethodTranslator.Translate(ExpressionConverter
    parent, MethodCallExpression call, SequenceMethod sequenceMethod)
           at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter
    parent, MethodCallExpression linq)
           at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator<code>1.Translate(ExpressionConverter
    parent, Expression linq)
           at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression
    linq)
           at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.Convert()
           at System.Data.Entity.Core.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable</code>1
    forMergeOption)
           at System.Data.Entity.Core.Objects.ObjectQuery<code>1.&lt;&gt;c__DisplayClass7.&lt;GetResults&gt;b__6()
           at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func</code>1
    func, IDbExecutionStrategy executionStrategy, Boolean
    startLocalTransaction, Boolean releaseConnectionOnSuccess)
           at System.Data.Entity.Core.Objects.ObjectQuery<code>1.&lt;&gt;c__DisplayClass7.&lt;GetResults&gt;b__5()
           at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func</code>1
    operation)
           at System.Data.Entity.Core.Objects.ObjectQuery<code>1.GetResults(Nullable</code>1
    forMergeOption)
           at System.Data.Entity.Core.Objects.ObjectQuery<code>1.&lt;System.Collections.Generic.IEnumerable&lt;T&gt;.GetEnumerator&gt;b__0()
           at System.Data.Entity.Internal.LazyEnumerator</code>1.MoveNext()
           at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable<code>1 source)
           at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.&lt;GetElementFunction&gt;b__1[TResult](IEnumerable</code>1
    sequence)
           at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable<code>1
    query, Expression queryRoot)
           at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute[TResult](Expression
    expression)
           at System.Data.Entity.Internal.Linq.DbQueryProvider.Execute[TResult](Expression
    expression)
           at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable</code>1 source)
           at Neon.DBHandler.registerStudentCourses(String p, List`1 coursesIdSelected) in
    c:\Users\AbdullahABBASI\Desktop\AbbasiWebProject\Neon\Models\DBHandler.cs:line
    246
           at Neon.Student_RegisterCourse.registerbutton_Click(Object sender, EventArgs e) in
    c:\Users\AbdullahABBASI\Desktop\AbbasiWebProject\Neon\Student_RegisterCourse.aspx.cs:line
    51
           at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
           at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
           at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
    eventArgument)
           at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
           at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
           at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)<br>
    InnerException:</p>
  </blockquote>
  
  <p>Code is below:</p>
  
  <pre><code>internal static void registerStudentCourses(string p, List&lt;string&gt; coursesIdSelected)
  {
      AbbasiDatabaseEntities objDB = new AbbasiDatabaseEntities();
      Student objStudent = objDB.Students.Where(s =&gt; s.Id == p).FirstOrDefault();
      List&lt;Course&gt; courses = new List&lt;Course&gt;();
  
      for (int i = 0; i&lt;coursesIdSelected.Count; i++)
      {
          //in the line below i am getting exception mentioned above
          var course = objDB.Courses
              .Where(c =&gt; c.Id == (string)coursesIdSelected.ElementAt(i))
              .Select(s=&gt; s)
              .FirstOrDefault();
          courses.Add(course);
      }
  
      objStudent.Courses = courses;    
  } 
  </code></pre>