| Thomas's profileBlogsBlogLists | Help |
|
03 March Intersection with Linq2SQLImagine you have a data table that is specified as followed:
CREATE TABLE MyTable
ArticleId int NOT NULL,
CategoryId int NOT NULL and you want to return all article ids that interesect with an array of Category Id's using LINQ2SQL.
Here is a solution:
int[] categoryIds = new int[] {29,5201,4}; IQueryable<ObjectNodeView> result = context.MyTable; // make a select for the first category: int firstCategory = categoryIds.First(); result = from a in result where a.CategoryId == firstCategory select a; // now intersect all other categories using a inner join: foreach(int categoryId in categoryIds.Skip(1)) { result = from a in result join a2 in context.MyTable on a.ArticleId equals a2.ArticleId where a2.CategoryId == categoryId select a; } TrackbacksThe trackback URL for this entry is: http://thomasgerber.spaces.live.com/blog/cns!58B30559C82E269C!680.trak Weblogs that reference this entry
|
|
|