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
Post a Comment