Table data is:
Info
----------------------------------------
num name age expenseN cost group
1 a 20
2 b 21
InfoDetail
----------------------------------------
num expenseN cost group
1 001 10.00 x
2 001 20.00 x
3 002 20.00 x
4 003 30.00 y
This is code:
public class _infoRepository
{
public string name { get; set; }
public int age { get; set; }
public string expenseN { get; set; }
public decimal cost { get; set; }
public string group { get; set; }
}
public class _infoDetailRepository
{
public string expenseN { get; set; }
public decimal cost { get; set; }
public string group { get; set; }
}
List<Info> result = new List<Info>();
var info = _infoRepository.Query(p => p.name = "a").FirstOrDefault();
var listInfoDetail = _infoDetailRepository.Query(p => p.group == "x").ToList();
for (int i = 0; i < listInfoDetail.Count; i++)
{
result.Add(new Info()
{
name = info.name,
age = info.age,
expenseN = listInfoDetail[i].expenseN,
cost = listInfoDetail[i].cost,
group = listInfoDetail[i].group
});
}
return result;
After running this code, the result of the result
variable is as follows:
result
--------------------------------------------------
num name age expenseN cost group
1 a 20 001 10.00 x
2 a 20 001 20.00 x
3 a 20 002 20.00 x
However, that was not the result I wanted, the result I expected was like this:
result
--------------------------------------------------
num name age expenseN cost group
1 a 20 001 30.00 x
2 a 20 002 20.00 x
After all, i want to group by and sum the result
variable to give me the desired result. Someone please help me in this situation, thanks