Saturday 15 March 2014

c# - LINQ IEnumerable OrderBy -


I am trying to implement filtering / order / paging on the data set. I filter by a search string I want to apply the order, then the subset of that set should be a page.

The code looks like this:

  IEnumerable & lt; Manufacturer & gt; Manufacturers; If (String.IsNullOrEmpty (genericSearch)) {manufacturers = DB. Where (L = & gt; l.Name.Contains (General Search)); } Manufacturers = manufacturers. Orderbie (sort code, sort deer, true); // It will not build if it will build // Before I 'db.mainufacturers' Order bye but then I lose my filter. This // will also be created if I 'l = & gt; OrderBy parameter as 'L.Name' but I have only the column name // as the string from the client. the creator. Skip (display). Move (display lengths) .Oolist (). For (REC => Aadata.ed (RE. Properties Technologists ())); // This is paging where I can use ToList ()   

How do I order a column name with a string?

One of the possible ways to use reflection

  public Fixed IEnumerable & lt; T & gt; Sort & lt; T & gt; (This IEnumerable & lt; T & gt; list, string column, sorted direction = sorted allocation. Allocation) {Func & lt; T, Object & gt; Selector = P = & gt; P. Gettype () GetProperty (column). Gate value (p, empty); Return (direction == sorting date.exing? Catalog.orderbay (selector): list.orderbirdcending (selector)); }    

No comments:

Post a Comment