简体   繁体   English

导致此错误的原因:类型'System.String'不支持序列运算符

[英]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.

相关问题 类型&#39;System.String&#39;不支持序列运算符。 - Sequence operators not supported for type 'System.String'. Linq-to-Sql - 类型&#39;System.String&#39;不支持的序列运算符 - Linq-to-Sql - Sequence operators not supported for type 'System.String' 类型&#39;System.String []&#39;不支持比较运算符 - Comparison operators not supported for type 'System.String[]' 获取错误类型&#39;System.String&#39;不支持数组反序列化 - Getting error Type 'System.String' is not supported for deserialization of an array 数组的反序列化不支持类型“System.String” - Type 'System.String' is not supported for deserialization of an array 数组不支持Type.String - Type System.String is not supported of an array 使用 JSON.stringify 的“类型 System.String 不支持反序列化数组”错误 - "Type System.String is not supported for deserialization of an array" error using JSON.stringify 从'System.String []'转换object类型到类型'System.IConvertible'错误意味着什么 - what does casting object type from 'System.String[]' to type 'System.IConvertible' error mean Linq问题:类型&#39;System.String []&#39;的表达式不是序列 - Linq problem: The expression of type 'System.String[]' is not a sequence ExpressionTree-GetSetMethod错误:未为类型&#39;System.String&#39;定义方法&#39;System.String get_Name()&#39; - ExpressionTree - GetSetMethod Error: Method 'System.String get_Name()' is not defined for type 'System.String'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM