Quantcast
Channel: C1 CMS Foundation - Open Source on .NET
Viewing all articles
Browse latest Browse all 2540

New Post: what's the best way/practice of handling many to many in C1

$
0
0
Lets say you save all tags an article has in a TagIds property on the Article datatype.

On the home page, you would of course just list all tags you have. When you need a list of articles within a tag you execute the query i showed earlier
var articlesContaingTag = data.Get<IArticle>().Where(a => a.TagIds.IndexOf(tag.Id.ToString(), StringComparison.OrdinalIgnoreCase) > -1).ToList();
Its not you who goes through every article, its the datalayer, and trust me, its fast enough.

To list all tags an article has you just do this
var tagIds = article.TagIds.Split(new [] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(id => Guid.Parse(id));
var tags = tagIds.Select(id => data.Get<ITag>().SingleOrDefault(t => t.Id == id);
This is also fast enough, since the datalayer is smart enough to cache lookups using the Key of a datatype. Its like doing a dictionary lookup.

Viewing all articles
Browse latest Browse all 2540

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>