【发布时间】:2017-07-28 10:04:12
【问题描述】:
我有一个网格/集合对象(我们称之为 SELECT_RESULTS),它是 IList、ICollection、IEnumberable 的子对象。
SELECT_RESULTS 填充有 PL/SQL SELECT 存储过程的返回结果。
我有两个问题: 1) 我无法在我的 foreach 循环中访问 SELECT_RESULTS 的字段,并且 2) 我需要根据 SELECT_RESULTS 集合的主键值将另一个从 LINQ SELECT 派生的字段值添加到此集合中。
这是我迄今为止尝试过的:
// get the list of potential CUST_NAME that will be appended
var q = (from tableX in dbContext.CUSTOMER
where tableX.CUST_ID = 42
select new
{
tableX.CUST_ID
tableX.CUST_NAME
tableX.A_DATE
} );
// trying to get results to know what type it's a collection of:
var results = SELECT_RESULTS as CollectionOfPeople;
// dilemma : item is an Object here, so I'm unable to access the
// different field names in the collection :-(
foreach (var item in results)
{
// question1) how to find the matching row in the collection.
// I am unable to see item.ID.
// Only can see item.ToString, item.ToHashCode, and other Object stuff
var q1 = q.Where (x => x.CUST_ID == item.ID);
// question 2) I need to Append the CUST_NAME into the collection
// onto the row having matching CUST_ID == ID
???
}
【问题讨论】:
标签: c# asp.net entity-framework linq collections