I was unsure if what I wrote as a Title would suffice, but I will do my best to explain what I am trying to accomplish here:
I am trying to recreate this query that I use to look up distinct data from TestColumn:
List<string> groupQuery = (from p in testDepo
group p by new { p.TestColumn}
into distinctTest
select distinctTest.First().TestColumn).ToList();
But instead of statically call TestColumn. I would like to dynamically pass in the name: TestColumn into a variable and then do my distinct value query using the variable name.
So far I have this:
string primaryColumn = "TestColumn"
List<string> groupQuery= (from p in testDepo
group p by new { primaryColumn }
into distinctTest
select distinctTest.First().GetType().GetProperty(primaryColumn).GetValue(distinctTest.First()).ToString()).ToList();
I know i am probably doing something silly, but i cant quite wrap my head around it right now. my dynamic query only half works. It is only getting the first distict value, but not the rest of them. Can anyone help me out?
pin your query?pis the object that i am trying get distinct values from.TestTestjust like your table name.