tag:blogger.com,1999:blog-7019647876740621435.post5928668727661371993..comments2023-01-26T17:42:45.444-06:00Comments on AOnNull: Dynamic SQL-like Linq OrderBy ExtensionAdam Andersonhttp://www.blogger.com/profile/17078340429103638232noreply@blogger.comBlogger30125tag:blogger.com,1999:blog-7019647876740621435.post-44951175128540943292017-01-28T15:02:39.629-06:002017-01-28T15:02:39.629-06:00This code works great - exactly what I needed for ...This code works great - exactly what I needed for multi-column sorting, except that it fails in a UWP Release build targeting the .NET Native tool chain. the solution is to add, in your projectname.rd.xml file, the following:<br /><br />Type Name="System.Linq.Queryable" Browse="Required Public" Dynamic="Required Public"Anonymoushttps://www.blogger.com/profile/16715418241376459912noreply@blogger.comtag:blogger.com,1999:blog-7019647876740621435.post-44165513464590875162014-06-19T12:31:34.420-05:002014-06-19T12:31:34.420-05:00Hi Adam,
I was wondering if you could get in touch...Hi Adam,<br />I was wondering if you could get in touch with me in regards to licensing of this code. Could you email me at greg.boudreau@gmail.com?<br />Thanks!Anonymoushttps://www.blogger.com/profile/15627547527923328169noreply@blogger.comtag:blogger.com,1999:blog-7019647876740621435.post-38250392751378869222013-12-19T14:00:19.128-06:002013-12-19T14:00:19.128-06:00This class is just great and I've used it for ...This class is just great and I've used it for years! Thanks.<br /><br />It fails in a way I don't manage to solve though; If I sort by a child object and any item in the collection has NULL in the path, a NullException is thrown. <br /><br />Example: I want to sort on "Stock.Shipping.Tour.Name" and one item has Tour = null.<br /><br />I'd really appreciate if you can hint how to sprt such objects at the top or bottom instead of crashing.Anonymoushttps://www.blogger.com/profile/12419822698897803787noreply@blogger.comtag:blogger.com,1999:blog-7019647876740621435.post-44445842946948352582013-12-16T20:18:58.489-06:002013-12-16T20:18:58.489-06:00@a lost soul, if I understand your problem correct...@a lost soul, if I understand your problem correctly, you have a class Car with property Name that inherits from class Vehicle that doesn't have a property Name. You have an ICollection<Vehicle> that you want to order by "Name" using this extension?<br /><br />The way this method works, you would be bound by the same rules as if you called OrderBy<TSource,TKey>(Func<TSource,TKey>), which is to say, the only properties available would be ones available on TSource e.g. Vehicle or one of its base classes.<br /><br />One simple option might be, assuming Name is common to Car and Vehicle, you could move it to the base class, which would allow you to order by it using this method.<br /><br />Another simple option would be to filter the list to a specific type before Ordering with something like .OfType<Car>()<br /><br />Or a combo of the two above, create a interface INamedVehicle { string Name { get; } } that is implemented by Car, and cast the collection to that with .OfType<INamedVehicle>() prior to ordering <br /><br />One other option, that is a decidedly more complex, and less generic, but could be as "dynamic" as the posted method would be to create a custom IComparer<Vehicle> that has more knowledge of the type hierarchy, that takes a property list as a string and can do custom comparison logic based on type and property. Then use OrderBy(item => item, new MyVehicleComparer("Name"))<br /><br />Hope that helps.Adam Andersonhttps://www.blogger.com/profile/17078340429103638232noreply@blogger.comtag:blogger.com,1999:blog-7019647876740621435.post-5960448744723667152013-12-16T11:11:18.373-06:002013-12-16T11:11:18.373-06:00Love this little piece of code that solves tons of...Love this little piece of code that solves tons of coding needs for dynamic sorting. But I've run into an issue with ICollection sorting. For example if Object Vehicle contains Cars, so if i were to attempt to sort on Cars.Name ASC the property name does not exist on ICollection.<br /><br />Any suggestions?a lost soulhttps://www.blogger.com/profile/00325500490015348164noreply@blogger.comtag:blogger.com,1999:blog-7019647876740621435.post-45266053621823788892013-08-14T21:46:01.991-05:002013-08-14T21:46:01.991-05:00This was a fantastic help, thanks! Like Troy, I ne...This was a fantastic help, thanks! Like Troy, I needed it to work with jTable.<br /><br><br />btw, using ReSharper, the OrderBy method on IQueryable reduced to a single line:<br /><br><br />return ParseOrderBy(orderBy).Aggregate(collection, ApplyOrderBy);Anonymoushttps://www.blogger.com/profile/11007198447347972219noreply@blogger.comtag:blogger.com,1999:blog-7019647876740621435.post-3304325058594244832013-06-13T14:04:06.249-05:002013-06-13T14:04:06.249-05:00Thanks a lot!!great work!Thanks a lot!!great work!sanksurihttps://www.blogger.com/profile/05400635322977244035noreply@blogger.comtag:blogger.com,1999:blog-7019647876740621435.post-9124222948905054962013-03-29T00:36:57.262-05:002013-03-29T00:36:57.262-05:00You are awesome men, Good stuff...You are awesome men, Good stuff...Anonymoushttps://www.blogger.com/profile/05231540876997579793noreply@blogger.comtag:blogger.com,1999:blog-7019647876740621435.post-38715834705437104062013-02-22T08:16:51.001-06:002013-02-22T08:16:51.001-06:00Simple and Slick. Thanks!
I used this OrderByHelp...Simple and Slick. Thanks!<br /><br />I used this OrderByHelper to gracefully allow jtSorting as input for my controller. <br /><br /><br />http://www.codeproject.com/Articles/277576/AJAX-based-CRUD-tables-using-ASP-NET-MVC-3-and-jTaAnonymoushttps://www.blogger.com/profile/09688123075312629993noreply@blogger.comtag:blogger.com,1999:blog-7019647876740621435.post-89497669496040019252013-02-15T14:47:20.469-06:002013-02-15T14:47:20.469-06:00This solution don't works with collections of ...This solution don't works with collections of extended class. Returns me a error of conflict of types. Anybody knows how to resolve?Bernardo Loureirohttps://www.blogger.com/profile/05924284779707360606noreply@blogger.comtag:blogger.com,1999:blog-7019647876740621435.post-83062093668645883592013-02-08T16:07:12.427-06:002013-02-08T16:07:12.427-06:00Great job, thank You!Great job, thank You!Anonymoushttps://www.blogger.com/profile/07873607139657435806noreply@blogger.comtag:blogger.com,1999:blog-7019647876740621435.post-16197273977869095482012-09-13T18:07:09.532-05:002012-09-13T18:07:09.532-05:00It actually turned out to be pretty easy. Just pu...It actually turned out to be pretty easy. Just put the following code as the first code in the OrderBy(this IQueryable collection, string orderBy) method:<br /><br /> if (orderBy == null || orderBy == string.Empty)<br /> {<br /> Type type = typeof(T);<br /> orderBy = type.GetProperties()[0].Name;<br /> }Brian McCordhttps://www.blogger.com/profile/15571898244615521026noreply@blogger.comtag:blogger.com,1999:blog-7019647876740621435.post-75734786020873769702012-09-13T17:34:27.157-05:002012-09-13T17:34:27.157-05:00That's great code! Thank you. I would reques...That's great code! Thank you. I would request one small change if you have a few minutes. It would be nice if null or an empty string were passed in for it to have a "Default Sort" (perhaps the first property on the object) and sort on that. The reason would be for following it up with .Skip(). Currently, if you pass in a null or empty, it just returns which would cause a .Skip() to fail. Adding a default sort would avoid that.Brian McCordhttps://www.blogger.com/profile/15571898244615521026noreply@blogger.comtag:blogger.com,1999:blog-7019647876740621435.post-17169484584961689322012-08-21T06:32:19.614-05:002012-08-21T06:32:19.614-05:00great work!! what about random? like Guid.NewGuid(...great work!! what about random? like Guid.NewGuid()?michelhttps://www.blogger.com/profile/09563035201217224672noreply@blogger.comtag:blogger.com,1999:blog-7019647876740621435.post-72672845710020903092012-07-11T10:15:11.634-05:002012-07-11T10:15:11.634-05:00Very Thanks,Very Thanks,İbrahim Uludağhttps://www.blogger.com/profile/00828453458394326048noreply@blogger.comtag:blogger.com,1999:blog-7019647876740621435.post-27101923515405640202012-05-27T04:07:08.184-05:002012-05-27T04:07:08.184-05:00Adam, really this is amazing, thanks a lot for thi...Adam, really this is amazing, thanks a lot for this great code!!!knitohttps://www.blogger.com/profile/18037452648551597034noreply@blogger.comtag:blogger.com,1999:blog-7019647876740621435.post-70257199111212674042011-12-15T09:01:37.333-06:002011-12-15T09:01:37.333-06:00great code!!great code!!Anonymoushttps://www.blogger.com/profile/08311199971321302528noreply@blogger.comtag:blogger.com,1999:blog-7019647876740621435.post-55251231656813283582011-12-04T20:27:44.612-06:002011-12-04T20:27:44.612-06:00Its a beautiful code!Its a beautiful code!Marciliohttps://www.blogger.com/profile/17941837434876075709noreply@blogger.comtag:blogger.com,1999:blog-7019647876740621435.post-69349215477151957732011-12-04T20:27:00.328-06:002011-12-04T20:27:00.328-06:00Tks a Lot!!Tks a Lot!!Marciliohttps://www.blogger.com/profile/17941837434876075709noreply@blogger.comtag:blogger.com,1999:blog-7019647876740621435.post-60093834487393224102011-08-22T03:58:20.370-05:002011-08-22T03:58:20.370-05:00Thanks a lot this has saved me HOURS
of work , Gre...Thanks a lot this has saved me HOURS<br />of work , Great coding .Lhttps://www.blogger.com/profile/01209158658768859898noreply@blogger.comtag:blogger.com,1999:blog-7019647876740621435.post-25356316144710230412011-06-22T09:59:27.073-05:002011-06-22T09:59:27.073-05:00Thanks so much for this. Saved me hours of work. C...Thanks so much for this. Saved me hours of work. Cheers!ChrisDhttps://www.blogger.com/profile/08265537190922064563noreply@blogger.comtag:blogger.com,1999:blog-7019647876740621435.post-85201965820273858472011-06-22T09:58:45.359-05:002011-06-22T09:58:45.359-05:00Thank you so much. Saved me so much time. Brillian...Thank you so much. Saved me so much time. Brilliant!ChrisDhttps://www.blogger.com/profile/08265537190922064563noreply@blogger.comtag:blogger.com,1999:blog-7019647876740621435.post-40577081861400881712011-05-31T20:41:04.986-05:002011-05-31T20:41:04.986-05:00Thanks a lot!!!Thanks a lot!!!Eric Khorhttps://www.blogger.com/profile/18304560063932340736noreply@blogger.comtag:blogger.com,1999:blog-7019647876740621435.post-27388694371426731012011-04-09T09:42:00.834-05:002011-04-09T09:42:00.834-05:00Very nice! You just saved my day!!! :) :)Very nice! You just saved my day!!! :) :)Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-7019647876740621435.post-84222792009905837612011-04-08T17:34:19.532-05:002011-04-08T17:34:19.532-05:00Excellent piece of code, thank you.Excellent piece of code, thank you.Unknownhttps://www.blogger.com/profile/01672998374276197317noreply@blogger.com