I have two tables "Category" and "Movie" with 1-M relationship ('CategoryID' is a Foreign Key in the table "Movie"). I'm using a ListView to list all Categories. Inside of my ListView is Repeater that loops through all movies within each category.
In my code-behind,I'm binding the ListView DataSource as follows:
MovieDBDataContext context = new MovieDBDataContext();
var categories = context.Categories.Select(x => x).OrderBy(x => x.Order).ToList();
ListView1.DataSource = categories;
ListView1.DataBind();
and I'm binding the Repeater DataSource in the markup as follows:
<asp:Repeater runat="server" ID="repeater" DataSource='<%# ((Category)Container.DataItem).CategoryItems.Where(p => p.Active == true).OrderBy(p => p.Name) %>'>
Now I'm having a requirement where I need sort my movie by name, but if a movie starts with "The " than I need to disregard that and sort on the rest of the name (so "The Lord of the rings" will be sorted as "Lord of the rings").
Is there a way to modify my Linq statement to manipulate strings in such a way on the fly?
((Category)Container.DataItem).CategoryItems.Where(p => p.Active == true).OrderBy(p => p.Name.StartsWith("The ") ? p.Name.Substring(4): p.Name)