Background
Currently I have a C# Silverlight business application which uses RIA Services. The application is hosted in ASP.NET using the ADO.NET Entity Framework and a domain service class to read and write to the SQL Server database.
Since the RIA class doesn't support multiple JOIN
s between tables, it was therefore necessary to implement LINQ as part of the domain service to JOIN
all the tables together and return results.
Problem
I get the error message when I try and use a foreach
loop on a returned list of objects:
Does not contain a public definition for GetEnumerator
What are my options for getting data out of this method?
Most of the time I only need one object, so I could just modify the method to select the first result and return a single object.
This method exists in the Domain Service Class. This method defines the context and then calls the method in the Silverlight client.
Method Invocation from Silverlight Client
var context = dds.DomainContext as InmZenDomainContext;
context.GetJobImagesQuery(imageJob.JobID.ToString())
Server Side Linq Query Method (Exists within Domain Service Class)
public List<Image> GetJobImages(string jobGuid)
{
var query =
(
from j in Context.Job
orderby (j.ShortCode)
where j.JobID.Equals(jobGuid)
join a in Context.Audit //.Distinct()
on j.JobID equals a.Job.JobID
join i in Context.Image
on a.Image.JobID equals i.JobID
//join s in Context.States
//on z.States.StateID equals s.StateID
select new Image
{
//ShortCode = j.ShortCode,
HighResUrl = i.HighResUrl,
LowResUrl = i.LowResUrl,
UploadDate = i.UploadDate
}).ToList();
return query;
}
Invocation method
var context = dds.DomainContext as InmZenDomainContext;
foreach (var item in context.GetJobImagesQuery(imageJob.JobID.ToString()))
{
}
GetJobImagesQuery
Declaration (Exists within the generated code file - .Web.g.cs):
/// <summary>
/// Returns an EntityQuery for query operation 'GetJobImages'.
/// </summary>
public EntityQuery<Image> GetJobImagesQuery(string jobGuid)
{
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("jobGuid", jobGuid);
return base.CreateQuery<Image>("GetJobImages", parameters, false, true);
}