所以我有这个问题:
using (APContext _context = new APContext(null)) {
var q = from inv in _context.Invoices
where inv.Sys_InvoiceID == 1276291
join cust in _context.InvoiceCustomFields
on inv.Sys_InvoiceID equals cust.FK_SysInvoiceID
select new {
inv.Sys_InvoiceID,
inv.AccountNumber,
cust.FK_CustomFieldHeader,
cust.Value
};
}
返回类似{ 1, 50, "Badger", "Is Great"}, { 2, 51, "Cat", "Is Cool"}
所以我在列表中有两个项目(如上所示),我需要将两个FK_CustomFieldHeaders值用作匿名列表中的属性,如下所示:
var x = q.Select(r => new{
ID = r.Sys_InvoiceID,
AccountNum = r.AccountNumber,
//Loop here and use reflectionto set CustomFieldHeader value as the property name and cust.Value to be the value for the property
});
我该怎么做?
编辑:我的问题不同,因为我不是在谈论在这里设置一个属性。查询返回两个。检查更新。
编辑2:它不一定是反思。我想请一些帮助和解释。