Dynamic sort in .NET


Gravatar Image
Lloyd Sheen 11/29/2021 10:57:42 PM
I have created the LinqExtension class in my app. I am at a loss how to use it though. If I simply copy the "Sort on property" code and replace the var context=new Context() with var context=teamrecords; I get an error and if I change that so it has using (List<VMTeamRecord> context = teamRecords) I still get an error. I am at a loss as how to use this
Gravatar Image
Jeffrey Rosselle 12/9/2021 9:56:50 AM
Hi Lloyd, what error are you getting? Keep in mind that context here is a DbContext and not a collection of entities. More info on how to use Extension Methods can be found here https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/extension-methods
Gravatar Image
shaq 2/19/2021 7:18:02 AM
Thanks a lot. Just got a question. As a newbie i dont understand the following code. Why checking if the childproperty is of generic type when in the both if and else clause you write the same code? property = SearchProperty(t, childProperties[i]);
Gravatar Image
Jeffrey Rosselle 2/19/2021 8:17:23 AM
Hmm good question... I might have had some other ideas there and forgot to remove the code completly. It's ben a while since I've written this. I've adjusted the code and removed the IF-statement. Thanks a lot for noticing!
Gravatar Image
Jhoel 2/18/2021 8:54:35 PM
Awesome Man thanks a lot.
Gravatar Image
Sandeep 11/11/2020 2:29:38 PM
Wonderful Job!! Made My Day!!