I have the following code:
ServiceSoapClient service = new ServiceSoapClient();
var dataSource = (from u in _db.Sessions
where u.DeletedOn == null
select new
{
SessionId = u.UploadSessionId,
FileName = u.FileName,
CreatedBy = u.User.UserName,
Partner = u.Company.Name,
CreatedOn = u.CreatedOn,
Visible = service.IsSessionProcessing(u.UploadSessionId)
})
.OrderByDescending(x => x.CreatedOn);
…of course the problem here is the Visible = service.IsSessionProcessing(u.UploadSessionId) portion that has access to modified closure because the expression is actually calculated when I use dataSource somewhere i.e preform .ToList() or something similar.
The problem here is that I can’t perform .ToList() immediately because I need to use it as a data source for a control as it is.
Is there any way to avoid this in Linq? Can I use a local variable in the expression itself so that it gets calculated with the real values?
The “modified closure” here is
service. So… don’t reassignservice.