我正在使用带有实体框架核心2.1和自动映射器3.2的.NET Core应用程序。在下面的脚本中,尝试ProjectTo(myviewClass)
时会得到空值并收到错误消息。现在,我知道可以通过do userRoleList.select(x=>x.ConsultationId) == null? null: projectTo
在以下脚本中检查单个值,但问题是它的集合,因此如何应用类似的逻辑,就像您看到的那样,我正在获取consultation
记录的集合ConsultationId
包含在userRoleLits
中。
(from user in Context.Users
join userRole in Context.UserRoles on user.Id equals userRole.UserId into userRoleList
where (user.Id == (UserId ?? user.Id))
select new UsersWithAccessProfileDataView
{
UserId = user.Id,
UserName = user.Name,
Consultation = Context.Consultations.Where(x => userRoleList.Select(y => y.ConsultationId).Contains(x.Id)).ProjectTo<ConsultationDataView>() //need help here
}).OrderBy(x => x.UserName);
public class UsersWithAccessProfileDataView
{
public Guid UserId { get; set; }
public string UserName { get; set; }
public IQueryable<ConsultationDataView> Consultation { get; set; }
}