I have the following Linq statement
from DataListItem dli in dlAttachments.Items
select new Objects.BHAttachment
{
Name = ((FileUpload)dli.FindControl("fuAttachment")).HasFile ? ((FileUpload)dli.FindControl("fuAttachment")).FileName : (((HyperLink)dli.FindControl("hypCurrentAttachment")).Text != null ? ((HyperLink)dli.FindControl("hypCurrentAttachment")).Text : ""),
Path = ((FileUpload)dli.FindControl("fuAttachment")).HasFile ? ((FileUpload)dli.FindControl("fuAttachment")).PostedFile.FileName : "",
FileUpload = ((FileUpload)dli.FindControl("fuAttachment")).HasFile ? ((FileUpload)dli.FindControl("fuAttachment")) : new FileUpload(),
DocumentType = ((Label)dli.FindControl("lblType")).Text,
URL = ""
}
And it works, very well. My question is about the constant re-referencing the FileUpload object. I am recreating (and refinding it) 6 times. Is there a way to set it once within Linq and refer to that single object?
You can use the
letstatement to create a variable