Skip to content

Instantly share code, notes, and snippets.

@TowardsDeath
Created March 1, 2011 11:39
Show Gist options
  • Save TowardsDeath/849013 to your computer and use it in GitHub Desktop.
Save TowardsDeath/849013 to your computer and use it in GitHub Desktop.
Find articles with all given tags (Linq/LLBLGen)
var tags = from t in data.Tag
where t.Title == tagTitle || t.Title == subTagTitle
select t.Id;
var list = ( from articlesWithTags in
(
from articleTag in data.ArticleTag
where tags.Contains( articleTag.TagId )
select articleTag
)
group articlesWithTags by articlesWithTags.ArticleId into grouped
let count = grouped.Count()
where count == tags.Count()
join a in data.Article on grouped.Key equals a.Id
select a ).Distinct().WithPath( path => path.Prefetch<ProfileEntity>( a => a.User )
.Prefetch<TagEntity>( a => a.TagCollectionViaArticleTag )
.FilterOn( t => t.TagForRole.Where( tr => tr.TagId == t.Id ).Count() == 0 ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment