【发布时间】:2019-04-15 21:31:19
【问题描述】:
我是 lambda 查询模型(我使用其他类进行投影 - GameBankVM、GameCouponBankVM),最后,我想循环查询结果并更新模型字段。但我得到实体或复杂类型“EPINMiddleWareAPI.Models.GameBankVM”无法在 LINQ to Entities 查询中构造。
这是我的示例代码:
var gameBankResult = await (context.GameBanks.Where(g => g.productCode == initiate.productCode)
.Take(initiate.quantity)
.Select(g => new GameBankVM
{
quantity = g.quantity,
currency = g.currency,
initiationResultCode = g.initiationResultCode,
productCode = g.productCode,
productDescription = g.productDescription,
referenceId = g.referenceId,
responseDateTime = g.responseDateTime,
unitPrice = g.unitPrice,
totalPrice = g.totalPrice,
coupons = g.coupons.Select(c => new GameCouponBankVM
{
Pin = c.Pin,
Serial = c.Serial,
expiryDate = c.expiryDate
}).ToList()
})).ToListAsync();
if (gameBankResult.Count() != 0)
{
foreach (var item in gameBankResult)
{
item.referenceId = initiate.referenceId;
context.Entry(item).State = System.Data.Entity.EntityState.Modified;
}
await context.SaveChangesAsync();
return Ok(gameBankResult);
}
如何更新我的 GameBank 模型/表上的 referenceId?
【问题讨论】:
标签: entity-framework rest asp.net-web-api lambda