I'm binding an ASP.NET control to the result of a LINQ query. I'd like to HtmlEncode one of the properties of the contained objects before binding to the control, but I want to do it without altering the data because I do a DataContext.SubmitChanges() later on. How can this be done?
Code that won't work:
var ds = (from s in dc.SearchResults
orderby s.datetime descending
select s)
.Take(int.Parse(ConfigurationManager.AppSettings["RecentItemQty"]));
foreach (SearchResult sr in ds)
sr.Query = Server.HtmlEncode(sr.Query);
rSearches.DataSource = ds;
rSearches.DataBind();