如何用此查询中名为ListOfAuditors的List中的值替换硬编码数组new int [] {102,7,39}?
public IList<UserDetails> GetAllAssociatesForGivenListOfAuditors(IList<UserDetails> ListOfAuditors)
{
using (OPMSDataSourceDataContext db = new OPMSDataSourceDataContext())
{
var query = (from AuditorAssociatemaps in db.AuditorAssociatemaps
where
(new int[] { 102, 7, 39 }).Contains(AuditorAssociatemaps.AuditorID)
group new { AuditorAssociatemaps.UserData, AuditorAssociatemaps } by new
{
AuditorAssociatemaps.UserData.FirstName,
AuditorAssociatemaps.AssociateID
} into g
orderby
g.Key.FirstName
select new UserDetails
{
FirstName = g.Key.FirstName,
UserID = g.Key.AssociateID
}).ToList();
return query;
}
}
答案 0 :(得分:2)
您可以尝试这样的事情:
...
var ids = ListOfAuditors.Select(a => a.Id)
...
,在查询中:
where ids.Contains(AuditorAssociatemaps.AuditorID)