score:3

Accepted answer

Since you're using LinqToSql, you should use DataContext.LoadWith when you fetch your objects. This is the preferred way of telling LinqToSql what it should pull down (since it defaults to lazy load).

DataLoadOptions options = new DataLoadOptions();
options.LoadWith((Employee c) => c.Rota);
db.LoadOptions = options;

http://msdn.microsoft.com/en-us/library/system.data.linq.dataloadoptions.loadwith.aspx

This has the benefit of being far more efficient on the SQL-side when compared with calling ToList or expanding EntityRef properties individually.

score:0

I assume Rota is contained in a collection. Set the collection type as List<Rota>, this should work if this is the case.

score:0

You are on the right track already - the query only gets executed once you iterate it (inspecting it in debug mode causes this iteration as well). Just call ToList() on the IQueryable (thus iterating it) before sending it through the web service.


Related Articles