Created
December 13, 2016 07:45
-
-
Save KennethanCeyer/5872d02cad683cee74e7b17a741ef7bd to your computer and use it in GitHub Desktop.
This is a guideline to how make to complex linq for applied the group clause in the models.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TestModel | |
{ | |
public int columnA; | |
public int columnB; | |
public int columnC; | |
public string columnD; | |
} | |
[HttpPost] | |
public JsonResult ModelLoad() | |
{ | |
List<TestModel> testModelList = new List<TestModel>(); | |
Dictionary<Tuple<int, int>, string> resultModel = new Dictionary<Tuple<int, int>, string>(); | |
for (int i=0; i<50; i++) | |
{ | |
testModelList.Add(new TestModel() | |
{ | |
columnA = i % 3, | |
columnB = i, | |
columnC = i % 4, | |
columnD = string.Format("string {0}", i.ToString()) | |
}); | |
} | |
testModelList.GroupBy(x => new | |
{ | |
x.columnA, | |
x.columnC | |
}) | |
.ToList() | |
.ForEach(g => | |
{ | |
var stringList = new List<string>(); | |
g | |
.ToList() | |
.ForEach(z => | |
{ | |
stringList.Add(z.columnB.ToString()); | |
}); | |
resultModel[Tuple.Create<int, int>(g.Key.columnA, g.Key.columnC)] = string.Join(", ", stringList); | |
}); | |
return APPActor.GetJson(resultModel); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment