Ugly linq query of the day:
Code:
var q = (
from c in db.tblTags
where
!(from o in db.tblTagSynonyms
select o.SynonymTagID)
.Contains(c.ID)
&&
c.Name.CompareTo(AnchorTagName) < 1
orderby c.Name descending
select new
{
c.ID,
c.Name,
c.Priority,
TotalResources = (from a in db.tblTagAnchors where a.TagID == c.ID select new { a.ID }).Count()
}
).Take(8).ToArray().Reverse().Union(
from c in db.tblTags
where
!(from o in db.tblTagSynonyms
select o.SynonymTagID)
.Contains(c.ID)
&&
c.Name.CompareTo(AnchorTagName) >= 1
orderby c.Name ascending
select new
{
c.ID,
c.Name,
c.Priority,
TotalResources = (from a in db.tblTagAnchors where a.TagID == c.ID select new { a.ID }).Count()
}
).Skip(1).Take(13).ToArray();
Given an alphabetical list of tags, given a tag "Tutorial", how do you return the 5 tags before it and the 5 after? Turns out to be a bit of a problem query lol. Took me a while to figure out, it looks gross but it works 100% fine, if anyone knows a better way of doing this in LINQ or SQL let me know I'd be interested!