views:

101

answers:

4

I am getting this error when I use the Linq expression of

var emp = _testModel.Where(m => m.Date == DateTime.Now).Select(m=>m);

The error is

'System.Collections.Generic.IEnumerable<TestModel>' does not contain a definition for 'System' and no extension method 'System' accepting a first argument of type 'System.Collections.Generic.IEnumerable<TestModel>' could be found (are you missing a using directive or an assembly reference?). 

I have google'd and looked everywhere by I have no idea what it is talking about? It doesn't throw an exception. The only way I found out about this was stepping through the expression.

Namespaces that are imported

using System;
using System.Collections;
using System.Linq;
using System.Collections.Generic;

Tried something like this and it still gives erros

string[] digits = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };

    var shortDigits = digits.Where((digit, index) => digit.Length < index);
+2  A: 

maybe you should put

using System.Linq;

at the start of your cs file.

See here for a similar case.

Ngu Soon Hui
It was already in my file.
That is System.Linq
leppie
A: 

Could be that _testModel is of type IEnumerable and not IEnumerable(Of T) the non generic IEnumerable does not have an extension method Where.

You could try

var emp = _testModel.OfType<T>().Where(p => p.Date == DateTime.Now);

where T should be the type of the generic enumerable you want in this case the type that you want p to be.

Cornelius
Nope, Doesnt work still. I even tried the second example I posted. Still the same error which is weird.
@user275561 I tried the second example as is and it works fine. Perhaps there is code before or after it that breaks? Have you tried the second example with no other code with it?
Cornelius
+1  A: 

It must be a problem in part of the code you're not showing us. This code compiles fine using .NET 3.5:

using System;
using System.Collections;
using System.Linq;
using System.Collections.Generic;

class TestModel
{
    public DateTime Date { get; set; }
}

class Test
{
    public void TestFunction()
    {
        IEnumerable<TestModel> _testModel = new TestModel[] { new TestModel() };
        var emp = _testModel.Where(m => m.Date == DateTime.Now).Select(m => m);

        string[] digits = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };
        var shortDigits = digits.Where((digit, index) => digit.Length < index);
    }
}
Foole
A: 

Turns out there is a bug in the Windows phone 7 series and it was preventing me from looking into the results.