How to merge based on Id.
public class StudentDetail
{
public string Id { get; set; }
public SubjectDetail SubjectDetails { get; set; }
}
public class SubjectDetail
{
public string Key { get; set; }
public string Value { get; set; }
}
public class StudentRequest
{
public List<StudentDetail>? StudentDetails { get; set; }
}
[0] Id = 1 , SubjectDetails = {Key = 1, Value= English}
[1] Id =1 , SubjectDetail = {Key =2 , Value = Math}
[2] Id =2 , SubjectDetail = {Key =2 , Value = Hindi}
[3] Id =3 , SubjectDetail = {Key =2 , Value = Science}
It should be like this ----
[0] Id = 1, SubjectDetails = [ [0] {Key = 1, Value= English} [1] {Key = 1, Value= English} ]
[2] Id =2, SubjectDetail = [[0]{Key =2 , Value = Hindi}]
[3] Id =3, SubjectDetail = [[0]{Key =2 , Value = Science}]
Here we have two id which are 1 but have different data. It should merge with with index 0 and index 1 will be id 2.
[{
"Id": "1",
"SubjectDetail": {
"Key": "2",
"Value": "3"
}
}, {
"Id": "1",
"SubjectDetail": {
"Key": "3",
"Value": "4"
}
}, {
"Id": "2",
"SubjectDetail": {
"Key": "6",
"Value": "7"
}
}
]