我第一次使用 LINQ 并有以下查询:
var query = from c in context.Call
join d in context.CallData on c.CallID = d.CallID
where c.CallID == 123
select new {
c.CallID,
c.CallResult,
d.FieldID,
d.FieldValue
};
这将返回类似于以下的数据
c.CallID c.CallResult d.FieldID d.FieldValue
123 Sale 345 John
123 Sale 346 Doe
123 Sale 347 888-222-3333
如何深入到包含 d.FieldID = 346 的行以获取 d.FieldValue 的值(346 是 LastName 字段)?我想将此值用作局部变量的新值:
// I know this doesn't work, just showing what I would like to accomplish
string LastName = query.Select(a => a.FieldID = 346).FieldValue;
相反,一旦获得这些结果,如何更改 c.CallResult 的值?既然是联接,我可以简单地更改一行数据还是必须进行单独的查询?