[英]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'. 我刚刚添加:&&!sp.KeyDeviceID.ToString()。Contains('〜'))现在,我得到奇怪的错误消息:类型'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?
有任何想法吗?
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)
. 我怀疑问题在于它正在使用
Enumerable.Contains(string, char)
(因为string
实现了IEnumerable<char>
),而您确实想要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: 请注意,如果
KeyDeviceID
已经是一个字符串属性,我将摆脱ToString()
调用:
!sp.KeyDeviceID.Contains("~")
Are you using Linq to SQL? 您正在使用Linq to SQL吗? Linq to SQL does not support all of the .Net functionality for data types.
Linq to SQL不支持数据类型的所有.Net功能。 You can use SQLFunctions to replicate some of the functionality.
您可以使用SQLFunctions复制某些功能。 If sp.KeyDeviceID is not a string, then using ToString() would throw an error if you are using Linq to SQL.
如果sp.KeyDeviceID不是字符串,那么如果您使用的是Linq to SQL,则使用ToString()会引发错误。 Try
尝试
IEnumerable<DataAccessLayer.SQLPendingEventRecord> dataset1 = _v3Context.SQLPendingEvents
.Where(sp => sp.EventType.ToString() == str100w && sp.EventDateTime > dtStartDate && !**SQLFunctions.CharIndex(sp.KeyDeviceID,"~")>0)**
.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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.