[英]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),其逻辑如下:
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.