简体   繁体   English

比较运算符不支持Linq查询中的'System.String []'

[英]Comparison operators not support for 'System.String[]' in a Linq query

I'm working on a Linq query to join data from two tables (using Linq to SQL), with the logic as follows: 我正在研究一个Linq查询,以连接来自两个表的数据(使用Linq到SQL),其逻辑如下:

  • Banners contains a field which has comma separated values in it. 标语包含一个带有逗号分隔值的字段。 I want to split this column and have a list of IDs (for example 1,2,3,4) 我想拆分此列并有一个ID列表(例如1,2,3,4)
  • References contains a list of these mappings with 1:1 mapping between the ID in banners and the ID in the reference table 引用包含这些映射的列表,横幅中的ID与引用表中的ID之间具有1:1映射
  • Once the tables are merged I want to return the description from the reference table, which is the text representation of the ID. 合并表后,我想从参考表返回描述,即ID的文本表示。

I've been fiddling with this for a while and have hit a brick wall. 我已经摆弄了一段时间,撞上了砖墙。 Below is the code I am using (in LinqPad): 以下是我正在使用的代码(在LinqPad中):

var results = (from b in Banners
         where b.BannerCode == "1234"
         from a in b.VesselBoatAreaY.Split (',').AsEnumerable()
         join r in References on a equals r.ReferenceCode
         where r.Context == "TestContext" 
         select r.Description).ToList();

I have confirmed that the first part of the query works, ie that banner code exists and returns 4 separate values. 我已经确认查询的第一部分有效,即横幅代码存在并返回4个单独的值。 When I run the query as a whole however I get the following: 当我整体运行查询时,得到以下信息:

NotSupportedException Comparison operators not supported for type 'System.String[]'. NotSupportedException类型'System.String []'不支持比较运算符。

I have also tried the following: 我也尝试了以下方法:

var results = (from b in Banners
               where b.BannerCode == "1234"
               from a in b.VesselBoatAreaY.Split (',').AsEnumerable()
               from r in References
               where r.Context == "TestContext" &&
               a.Contains(r.ReferenceCode)
               select r.Description).ToList();

When I run this I get the following: 当我运行它时,我得到以下信息:

ArgumentException ArgumentException
The argument 'value' was the wrong type. 参数“值”是错误的类型。 Expected 'System.String'. 预期为“ System.String”。 Actual 'System.String[]'. 实际的“ System.String []”。

Any help appreciated! 任何帮助表示赞赏!

Thanks for everyones help. 谢谢大家的帮助。 I've solved the problem and it was actually very easy. 我已经解决了这个问题,实际上很容易。 As the table I am reading from is quite small I can apply AsEnumerable to the Banners table and it works fine. 由于我要读取的表很小,因此我可以将AsEnumerable应用于Banners表,并且工作正常。 I realise this means it will get processed in memory, so it's not good for bigger tables, but its fine for what I need. 我意识到这意味着它将在内存中进行处理,因此它不适用于较大的表,但可以满足我的需要。

For reference the code is now: 供参考,代码现在为:

var results = (from b in Banners.AsEnumerable()
               where b.BannerCode == "1234"
               from a in b.VesselBoatAreaY.Split (',')
               from r in References.AsEnumerable()
               where r.Context == "TestContext" &&
               a.Contains(r.ReferenceCode)
               select r.Description).ToList();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 类型'System.String []'不支持比较运算符 - Comparison operators not supported for type 'System.String[]' Linq查询不支持System.String - Linq query doesn't support System.String Linq-to-Sql - 类型'System.String'不支持的序列运算符 - Linq-to-Sql - Sequence operators not supported for type 'System.String' 类型'System.String'不支持序列运算符。 - Sequence operators not supported for type 'System.String'. LINQ to Entities无法识别方法'System.String getFullname(System.String,System.String)' - LINQ to Entities does not recognize the method 'System.String getFullname(System.String, System.String)' LINQ to Entities 无法识别“System.String Decrypt(System.String, System.String)”方法 - LINQ to Entities does not recognize the method 'System.String Decrypt(System.String, System.String)' method Linq查询结果不支持类型'System.Linq.IQueryable`1 [System.Int32]的比较运算符 - Linq query results in Comparison operators not supported for type 'System.Linq.IQueryable`1[System.Int32] 对Xdocument的Linq查询返回“System.linq.Enumerable + WhereSelectEnumerableIterator'2 [system.XML.Linq.Xelement,System.String] - Linq query on Xdocument returns "System.linq.Enumerable+WhereSelectEnumerableIterator'2[system.XML.Linq.Xelement,System.String] LINQ 到实体无法识别 System.String - LINQ to Entities Not recognize System.String 无法将类型为“ System.Double”的对象转换为类型为“ System.String”的linq查询 - Unable to cast object of type 'System.Double' to type 'System.String' linq query
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM