what causes this error: Sequence operators not supported for type 'System.String'

Here is my code:

    IEnumerable<DataAccessLayer.SQLPendingEventRecord> dataset1 = _v3Context.SQLPendingEvents
                     .Where(sp => sp.EventType.ToString() == str100w && sp.EventDateTime > dtStartDate && !sp.KeyDeviceID.ToString().Contains('~'))
                     .AsEnumerable() // further processing occurs on client
                     .Select((sp, index) => new DataAccessLayer.SQLPendingEventRecord
                     {
                         ID = index + 1,
                         KeyDeviceID=sp.KeyDeviceID,
                         UpdateTime=sp.UpdateTime,
                         EventClass=sp.EventClass,
                         EventCode=sp.EventCode,
                         EventType=sp.EventType,
                         EventDateTime=Convert.ToDateTime(sp.EventDateTime),
                         KeyPropertyID=Convert.ToInt32 (sp.KeyPropertyID),
                         KeyEntityID=Convert.ToInt32 (sp.KeyEntityID),
                         EventText=sp.EventText,
                         KeyUserID=sp.KeyUserID,
                         //sp.EventImage,
                         TaskType=sp.TaskType,
                         TaskSubType=sp.TaskSubType,
                         UniqueTaskID=sp.UniqueTaskID
                     }).ToList();

I have just added: && !sp.KeyDeviceID.ToString().Contains('~')) Now, I get odd error msg: Sequence operators not supported for type 'System.String'. Before that, I had no problem. Now, I get this cryptic error message. I need to put this all in one query, due to the size of the database. Any ideas?

Jon Skeet
people
quotationmark

I suspect the problem is that it's using Enumerable.Contains(string, char) (because string implements IEnumerable<char>) whereas you really want string.Contains(string).

Just changing it to:

!sp.KeyDeviceID.ToString().Contains("~")

may fix the issue.

Note that if KeyDeviceID is already a string property, I'd get rid of the ToString() call:

!sp.KeyDeviceID.Contains("~")

people

See more on this question at Stackoverflow