我在我的linq实体查询中得到一个例外
的异常LINQ表达式节点类型' NewArrayBounds' LINQ to Entities
不支持
当我尝试获取' RegisteredInstructorImage'
时以下是我为解决错误所做的工作
.Select(i => new EventResult
{
IsInstructorRegistered = i.RegisteredInstructor == null ? false : true,
RegisteredInstructorId = i.RegisteredInstructor != null ? i.RegisteredInstructor.YogaProfileId : 0,
RegisteredInstructorName = i.RegisteredInstructor != null ? i.RegisteredInstructor.FirstName : "",
RegisteredInstructorImage = i.RegisteredInstructor != null ? i.RegisteredInstructor.PrimaryImage11 : new byte[0],
RegisteredInstructorTotalReviews = i.RegisteredInstructor != null ? i.RegisteredInstructor.TotalReviews : 0,
}).ToPagedList(Page, 10);
在EventResult
中,我根据此SO post按照以下方式对其进行初始化,但这并未影响我的结果,我仍然得到错误。我在这里做错了吗?
public class EventResult
{
public EventResult()
{
RegisteredInstructorImage = new byte[] { 0 };
}
public byte[] RegisteredInstructorImage { get; set; }
}
答案 0 :(得分:0)
我建议改变:
i.RegisteredInstructor != null ? i.RegisteredInstructor.PrimaryImage11 : new byte[0]
为:
i.RegisteredInstructor?.PrimaryImage11
然后考虑更改RegisteredInstructorImage
的属性设置器,以便在需要时检查null
(并更改为空数组)。