我的代码如下
GetDairyHeaderInfoByEmail(id)
.Where(p => p.ATTRIBUTE15 == id)
.Select(jk=> new {
jk.HEADER_ID_PK,
jk.VENDOR_ID,
jk.VENDOR_SITE_ID,
jk.VENDOR_NAME,
jk.ADDRESS_LINE1,
jk.ATTRIBUTE15
})
.GroupBy(p => p.HEADER_ID_PK)
.Select(p => new {
header_id_pk = p.Key,
invoice_id_pk = _ippDetailServices.GetDairyHeaderInfoByEmail(id).Where(k => k.HEADER_ID_PK == p.Key).Select(c => new { c.APP_INVOICES_ID_PK, c.INVOICE_TYPES, c.IS_HOURLY }).ToList() }).ToList();
我看到的结果如下
[{ “header_id_pk”:800.0,
"invoice_id_pk": [ { "APP_INVOICES_ID_PK": 1058.0, "INVOICE_TYPES": "EPP", "IS_HOURLY": "Y" }, { "APP_INVOICES_ID_PK": 1059.0, "INVOICE_TYPES": "CPP", "IS_HOURLY": "Y" }, { "APP_INVOICES_ID_PK": 1060.0, "INVOICE_TYPES": "WHT ON DIVIDEND", "IS_HOURLY": "N" }, { "APP_INVOICES_ID_PK": 1061.0, "INVOICE_TYPES": "L.P", "IS_HOURLY": "N" } ] } ]
但我希望结果如下
[{
"header_id_pk": 800.0, "HEADER_ID_PK" : 800.0, "VENDOR_ID" : 12.0, "VENDOR_SITE_ID" : 33.0, "VENDOR_NAME" : Faisal, "ADDRESS_LINE1" : XYZ address, "invoice_id_pk": [ { "APP_INVOICES_ID_PK": 1058.0, "INVOICE_TYPES": "EPP", "IS_HOURLY": "Y" }, { "APP_INVOICES_ID_PK": 1059.0, "INVOICE_TYPES": "CPP", "IS_HOURLY": "Y" }, { "APP_INVOICES_ID_PK": 1060.0, "INVOICE_TYPES": "WHT ON DIVIDEND", "IS_HOURLY": "N" }, { "APP_INVOICES_ID_PK": 1061.0, "INVOICE_TYPES": "L.P", "IS_HOURLY": "N" } ] } ]
对于乱七八糟的遗憾,这是我的第一个问题。 感谢
答案 0 :(得分:1)
var dairy = _ippDetailServices.GetDairyHeaderInfoByEmail(id).Where(p =>
p.ATTRIBUTE15 == id).Select(jk=> new { jk.HEADER_ID_PK,
jk.VENDOR_ID,
jk.VENDOR_SITE_ID,
jk.VENDOR_NAME,
jk.ADDRESS_LINE1,
jk.ATTRIBUTE15
}).GroupBy(p => new { p.HEADER_ID_PK,
p.VENDOR_ID, p.VENDOR_SITE_ID,
p.VENDOR_NAME, p.ADDRESS_LINE1,
p.ATTRIBUTE15 }).Select(p => new {
header_id_pk = p.Key, invoice_id_pk =
_ippDetailServices.GetDairyHeaderInfoByEmail(id).Where(k => k.HEADER_ID_PK ==
p.Key.HEADER_ID_PK).Select(c => new { c.APP_INVOICES_ID_PK,
c.INVOICE_TYPES,
c.IS_HOURLY }).ToList() }).ToList();
我想通了,我只需要在Group By子句中添加这些主列。