The following LINQ:
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()
}
).ToList();
is giving me this error:
LINQ to Entities does not recognize the method
'System.Collections.Generic.List1[KernWcfTest.DataTransferObjects.JobDetailDto]
ToList[JobDetailDto](System.Collections.Generic.IEnumerable
1[KernWcfTest.DataTransferObjects.JobDetailDto])' method,
and this method cannot be translated into a store expression.
Here are the two dto classes:
[DataContract]
public class JobDetailDto
{
[DataMember]
public int ScreenFieldId { get; set; }
[DataMember]
public string FieldValue { get; set; }
}
[DataContract]
[KnownType(typeof(JobDetailDto))]
public class JobDto
{
[DataMember]
public int JobMasterId { get; set; }
[DataMember]
public string ExternalTaskId { get; set; }
[DataMember]
public List<JobDetailDto> JobDetails { get; set; }
}
The problem is the sub-select and the JobDetails list. I tried adding the KnownType but it didn't work.
This all works fine in LINQ Pad.
Any ideas?
Cheers
Steve