I have a function that returns a JsonResult which should be a list of all object types that are associated to the provided guid. But I’m getting the error
LINQ to Entities does not recognize the method ‘System.Type GetType()’ method, and this method cannot be translated into a store expression.
Is this possible?
public JsonResult GetWebObjectTypesByWebObject(Guid id)
{
JsonResult result = new JsonResult();
var resultData = (from w in db.WebObjects
from r in w.RelatedWebObjects
where w.Id == id
select new { Type = r.GetType().BaseType.Name });
result.Data = resultData;
result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
return result;
}
Try this:
You loose the deferred execution but it seems irrelevant in this case.