entity framework - LINQ to Entities does not recognize the method , method cannot be translated into a store expression -


     private void bindgrid()      {         advcontextef db = new advcontextef();         var query = r in db.mytable         orderby r.createdate descending        select new        {           r.id,           r.code,           r.mytable.relatedtables[0].thecenter.name         };          radgrid1.datasource = query.tolist();         radgrid1.databind();     } 

i got following error when running code above.

linq entities not recognize method 'advcontextef.mymethod get_item(int32)' method, , method cannot translated store expression.

thank you

instead of trying index r.mytable.relatedtables[0], try using .firstordefault().

      r.mytable.relatedtables.firstordefault().thecenter.name 

or

      name = r.mytable.relatedtables.select(rt => rt.thecenter.name).firstordefault() 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -