Я использую декомпилятор делегата в своем проекте. https://github.com/hazzik/DelegateDecompiler
Модель объекта (часть):
public long Id { get; set; }
public long ItemId { get; set; }
public long InfoItemId { get; set; }
[Computed]
public bool IsInfo
{
get
{
return (InfoItemId > 0 && ItemId == 0) ? true : false;
}
}
Модель приложения:
private class AttachmentModel
{
public string OriginalFileName { get; set; }
public string ItemFileType { get; set; }
public string Thumbnail { get; set; }
public string File { get; set; }
public string Category { get; set; }
public bool IsInfo { get; set; }
}
Запрос (часть):
Attachments = (from attachments in db.Attachments
where attachments.ItemId == i.Id || attachments.InfoItemId == infoId
select new AttachmentModel
{
OriginalFileName = attachments.ItemOriginalFileName,
ItemFileType = attachments.ItemFileType,
Thumbnail = attachments.FileThumbnailRelative,
File = attachments.FileUrlRelative,
Category = attachments.ItemFileCategory,
IsInfo = attachments.IsInfo.Computed()
}).ToList()
Но я получил ошибку:
LINQ to Entities does not recognize the method 'Boolean ComputedBoolean' method, and this method cannot be translated into a store expression.
В: Можно ли в этом случае использовать декомпилятор делегата? Как? Пожалуйста, приведите пример.





Здравствуйте, может будет полезно. Я нашел чрезвычайно полезный пост Dave Glick [post] (daveaglick.com/posts/computed-properties-and-entity-frameworkrk), в котором описаны различные решения. В моем случае вложения использовались в качестве подзапроса, поэтому, когда я использую и перемещаю метод «.Decompile» из подзапроса на верхний уровень запроса, это решает проблему для меня.