开发者

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. 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:

Error

Error 22 Operator '==' cannot be applied to operands of type 'int' and 'System.Collections.Generic.List<int>' C:\Docume开发者_运维问答nts 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>. They're totally different types. I think you want to do geographyList.Contains(cg.GeographyId) or some other operation like that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜