2012-04-03 47 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