Skip to content

Codepolice

  • ⤫

Create a tag cloud with a limited amount of tags in ASP.NET and LINQ

Posted by Judy Alvarez Posted on February 25, 2022March 1, 2022
0

Today I built a Tag cloud for my new site. I found this great article about how to do it with LINQ and C#. But I missed some features. Especially how to limit the number of tags that were shown. So if you read that article and then have a look at this code if you have the same problem as me.

var tagSummary = (from ti in db.TagItemRelations
	group ti by ti.Tag.Text into tagGroup
	select new {
	Tag = tagGroup.Key,
	TagFrequency = tagGroup.Count()
}).OrderByDescending(x=>x.TagFrequency).Take(20);

int maxTagFrequency = (from t in tagSummary select t.TagFrequency).Max();

var tagCloud = (from ti in tagSummary
	select new TagCloudItem {
	Tag = ti.Tag,
	Weight = (double)ti.TagFrequency / maxTagFrequency * 100
}).OrderBy(x=>x.Tag);

The main difference between my code and the code in the article is that I have a slightly more complex data model (should not matter) and that I make the second query against the “result” from the first query. This allows me to first order by popularity and then in alphabetic order.

Please leave a comment if there is any better way to do this or if you have any questions.

Categories: JavascriptTagged: asp . net interview questions, asp .net core, asp dot net, asp net 5, asp net ajax, asp net boilerplate, asp net cache, asp net caching, asp net core 5.0, asp net core webapi, asp net dropdownlist, asp net identity, asp net mvc 5, asp net nedir, asp net session management, asp net vs php, asp net web api interview questions, asp net webforms, asp net zero, asp. net, connection string in asp net, cookies asp net, framework asp net, interview questions on asp net, is asp net a framework, php vs asp net, query string in asp net, web services in asp net, what is asp net mvc

Post navigation

Previous Previous post: ASP.NET 4.0 – Some info from PDC
Next Next post: Using JQuery Validation plugin with ASP.NET

Related Posts

  • How JavaScript source maps actually work

    #​760 — November 7, 2025 Read on the Web JavaScript Weekly The Inner Workings of JavaScript Source Maps — Ever wondered how devtools can magically turn mangled, minified JavaScript back into readable source while debugging? Zero magic; that’s a source map doing its job. But how do source maps actually work under the hood? Manoj Vivek

    Posted by Posted on November 7, 2025
    0
  • Importing Node modules from BitTorrent?

    #​599 — November 4, 2025 Read on the Web Node v22 to v24 Migration Guide — Now that v24 is the new active LTS release, you might have code running on v22 you need to upgrade. The Node team has put together this helpful guide to the changes you’ll need to negotiate. There are similar

    Posted by Posted on November 5, 2025
    0
  • TypeScript and JavaScript dominate on GitHub in 2025

    #​759 — October 31, 2025 Read on the Web JavaScript Weekly Directives and the Platform Boundary — First there was the “use strict” directive to opt in to strict mode in JavaScript, but now you’ll encounter use client, use server, React’s new use no memo, and more, and they’re not standard JS features at all.

    Posted by Posted on October 31, 2025
    0
  • The reality of porting Deno code to Node

    #​598 — October 28, 2025 Read on the Web Awesome Node: Over 500 Curated Packages, Resources and Links — It’s been more than four years since we linked to Sindre’s handy resource, but it continues to get updates and tweaks (and, if you want, you can contribute a submission too – though the bar is

    Posted by Posted on October 28, 2025
    0
  • Vitest 4.0 and Next.js 16

    #​758 — October 24, 2025 Read on the Web JavaScript Weekly Vitest 4.0 Released: The Vite-Native Testing Framework — The Vite-powered, Jest-compatible testing framework introduces visual regression testing, makes its ‘Browser Mode’ stable (for running tests in a browser directly), adds Playwright Traces support, and more. Still unsure? You can compare it with other test

    Posted by Posted on October 24, 2025
    0
  • Node.js 25.0 arrives

    #​597 — October 21, 2025 Read on the Web Node.js v25.0.0 (Current) Released — The latest cutting edge version of Node has arrived with Web Storage enabled by default, JSON.stringify perf improvements, a new –allow-net option in the permission model, built-in Uint8Array base64/hex conversion, and WebAssembly and JIT optimizations. As shown in the diagram above, this

    Posted by Posted on October 21, 2025
    0
Judy Alvarez

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Codepolice

  • Github
  • Atlassian
  • Flatlogic
  • Xero
  • Jetbrains
  • Figma
  • How JavaScript source maps actually work
  • Importing Node modules from BitTorrent?
  • TypeScript and JavaScript dominate on GitHub in 2025
  • The reality of porting Deno code to Node
  • Vitest 4.0 and Next.js 16
https://flatlogic.com/generator
COPYRIGHT © 2025 - Codepolice