-3

How do i replace the hard coded array new int[] {102,7,39} by values from the List called ListOfAuditors in this query ?

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;
            }
        }
Chakra
  • 2,525
  • 8
  • 43
  • 82
  • You can find the item in a list [here][1] [1]: http://stackoverflow.com/questions/15281311/find-item-in-ilist-with-linq – nshah Aug 30 '14 at 16:39
  • 1
    Like you would literally, you select the text `new int[] { 102, 7, 39 }` and paste the text `ListOfAuditors` over it. – Benjamin Gruenbaum Aug 30 '14 at 16:40
  • You can find the item in a list [here][1] Also, pertinent [this example][2] [2]: http://stackoverflow.com/questions/9869908/how-to-use-ilist-contains-method-to-find-an-object – nshah Aug 30 '14 at 16:41
  • 1
    There is no way you wrote this and you are asking this question. Please ask the original author of the code, modifying other peoples code by using copy&paste from the internet is not getting you anywhere. Learn to write code yourself. – nvoigt Aug 30 '14 at 16:46
  • I am doing what you said @BenjaminGruenbaum. I am almost there i think. – Chakra Aug 30 '14 at 16:49

1 Answers1

2

You can try something like this:

...    
var ids = ListOfAuditors.Select(a => a.Id)
...

and, in the query:

where ids.Contains(AuditorAssociatemaps.AuditorID)
romanoza
  • 4,775
  • 3
  • 27
  • 44