2012-04-03 48 views
0

我有一個包含4列的表,即LoginID,LastName,FirstName,Email。 LoginID的數據從其他表填充。我必須編寫一個小例程來更新此表,方法是發送LoginID並在IDirectory例程的幫助下獲取姓氏,名字和電子郵件。這是我正在嘗試做的事情,但是對正確的語法感到困惑。更新表與來自IDirectory的信息

using (TSADRequestEntities context = UnityHelper.Resolve<TSADRequestEntities>()) 
{ 

    var fpvalues = context.FOCALPOINTs.ToList(); 
    foreach (var item in fpvalues) 
    { 
     IEnumerable<UserInfo> query = UnityHelper.Resolve<IUserDirectory>().Search(item.LoginID); 
     //Here, FocalPoint is the table that has the loginID and the other fields 
     //I need to update. the query shld now hv info on lastname etc..how do I 
     //retrieve that value and update the table? 

    } 
} 

回答

0

它有點很難告訴你的意思用正確的語法感到困惑,但你的下一步應該是

UserInfo info = UnityHelper.Resolve<IUserDirectory>().Search(item.LoginID. 
    .FirstOrDefault(); 

foreach循環中。然後,如果info != null,則將所需值複製到item對象。在與context.SaveChanges()關閉後foreach

+0

我在FirstOrDefault上失蹤,想知道如何獲得單獨一個記錄.Thx。 – sansid 2012-04-04 08:28:13