简体   繁体   English

LINQ-to-SQL:针对CSV搜索

[英]LINQ-to-SQL: Searching against a CSV

I'm using LINQtoSQL and I want to return a list of matching records for a CSV contains a list of IDs to match. 我正在使用LINQtoSQL,我想返回一个匹配记录列表,以便CSV包含要匹配的ID列表。 The following code is my starting point, having turned a CSV string in a string array, then into a generic list (which I thought LINQ would like) - but it doesn't: 下面的代码是我的出发点,已经将CSV字符串转换为字符串数组,然后转换为通用列表(我认为LINQ希望这样做)-但事实并非如此:

Error 错误

Error 22 Operator '==' cannot be applied to operands of type 'int' and 'System.Collections.Generic.List<int>' C:\Documents and Settings\....\Search.cs 41 42 C:\...\

Code

    DataContext db = new DataContext();

    List<int> geographyList = new List<int>( Convert.ToInt32(geography.Split(',')) );

        var geographyMatches = from cg in db.ContactGeographies
                               where cg.GeographyId == geographyList
                               select new { cg.ContactId };

Where do I go from here? 我从这里去哪里?

var geographyMatches = from cg in db.ContactGeographies
                               where geographyList.Contains(cg.GeographyId)
                               select new { cg.ContactId };

Like the error says, in where cg.GeographyId == geographyList you're trying to compare int to a List<int> . 就像错误所说的那样,在where cg.GeographyId == geographyList您试图将intList<int>进行比较。 They're totally different types. 它们是完全不同的类型。 I think you want to do geographyList.Contains(cg.GeographyId) or some other operation like that. 我认为您想执行geographyList.Contains(cg.GeographyId)或类似的其他操作。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM