-1

I have a piece of code

string phoneMobileW = null;
string phoneMobileP = null;
string phoneMain = null;
string phoneWork = null;
string phoneHome = null;

if (coreData.ListOfAddress_0006 != null && coreData.ListOfAddress_0006.Count() > 0)
{
    var phoneqry = from list in coreData.ListOfAddress_0006
        .Where(a => a.Subtype.ID == "1")
        .OrderByDescending(a => a.StartDate)
        .Take(1)
        .Where(p => p.ListOfPhoneNumber_0006 != null)
        .SelectMany(p => p.ListOfPhoneNumber_0006)
        select list;

    if (phoneqry != null)
    {
        var phoneList = phoneqry.ToList();
        phoneMobileW = phoneList
            .Where(q => q.NumberType.ID == "MOBW")
            .Select(q => q.Number)
            .LastOrDefault();
    }
}

The phone numbers are contained inside the address. If the address is not empty get the last phone number. However I have coped and pasted this piece of code over to another class it and it longer works. enter image description here

So where it works you can see the 'var' for phoneqry is interface System.Collections.Generic.Ienumerable

As I said I have copied it over to another class which is a unit testing class. I am trying to populate the phone number.

When I hold the cursor over var, nothing appears to show me what object it is(is this because its in a unitTest class?)

anyway the error I get is for .Where in var phoneqry = from list in coreData.ListOfAddress_0006.Where

Error 4 'System.Array' does not contain a definition for 'Where' and no extension method 'Where' accepting a first argument of type 'System.Array' could be found (are you missing a using directive or an assembly reference?) D:\MartinsCode\New folder\Trunk\BusinessLogic\SapEai.UnitTest\AdUnitTest.cs 166 73 RFS.BusinessLogic.SapEai.UnitTest

Thomas Levesque
  • 286,951
  • 70
  • 623
  • 758
John
  • 3,965
  • 21
  • 77
  • 163

1 Answers1

3

Where is a Linq extension method, you need to add this at the top of your file:

using System.Linq;

Alternatively, you can click on Where and press Ctrl+. on your keyboard, and it will prompt you to include the using for the System.Linq namespace.

See here for more information on what extension methods are.

ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
  • 1
    thank You that worked. I did previously right click on the object and choose resolve, i must have chose the wrong ref tho. thank you – John Nov 15 '17 at 00:46