Nested LINQ returning a this method cannot be translated into a store expression exception

前端 未结 1 1097
一整个雨季
一整个雨季 2021-01-05 18:11

The following LINQ:

retval = ( from jm in entities.JobMasters
                 where jm.UserId == userId && jm.IsRemote == false
                 sel         


        
1条回答
  •  -上瘾入骨i
    2021-01-05 18:56

    Don't call ToList on the inner query (the one for JobDetails). The error is "This .ToList method you speak of -- it can't be translated to T-SQL!"

    This should work:

    retval = ( from jm in entities.JobMasters
                 where jm.UserId == userId && jm.IsRemote == false
                 select new JobDto
                 {
                     JobMasterId = jm.JobMasterId,
                     ExternalTaskId = jm.ExternalTaskId,
                     JobDetails =   from jd in entities.JobDetails
                                    where jd.JobMasterId == jm.JobMasterId
                                    select new JobDetailDto { ScreenFieldId = jd.ScreenFieldId, FieldValue = jd.FieldValue }
                     )
                 }
            ).ToList();
    

    Note that you can call ToList on the end of the query, as that part doesn't need to be translated to T-SQL.

    0 讨论(0)
提交回复
热议问题