I am querying a set of Entity Framework objects and projecting them through a WCF RIA service into lightswitch.
In my query I perform a join between a couple of tables, one of which are details for a summary table. I want to determine which detail item is the 'first' item in the list and compare that to the current item in my projection during enumeration. The reason being in the projection I want to change which of my available properties sets this specific projection's property.
This is the query so reduced
var result = (from dataItem in (from x in Context.xs
join y in Context.ys
on x.property = y.property
select new {x, y})
.Select( (model, index) =>
new ObjectType
{
Id = index,
OneOfTwo = model.x.property,
(
from y in Context.ys
where y.SomeProperty == model.Property
select y)
.OrderBy(list=>list.Id)
.FirstOrDefault()
.ComparedProperty ==model.ComparedProperty
)
? model.AnotherProperty
: model.YetAnotherProerty
}
);
How can I evaluate that inner query without running into DataReader errors because I'm trying to use the Context while it is being read?
Update:
I did some research and realize that this is not a problem with linq to sql but it is a problem with linq to entities. Essentially that operation is the equivalent of using a parameterized query which isn't supported. What are the workarounds in this situation?